Docker Command Line Cheatsheet
# Build image
# -t : tag
# . : current dir
docker build -t username/image_name:tag_name .
# start image in bashDocker Command Line Cheatsheet
# Build image
# -t : tag
# . : current dir
docker build -t username/image_name:tag_name .
# start image in bash| import re | |
| from django.db import models | |
| from django.conf import settings | |
| from django.utils.translation import ugettext, ugettext_lazy as _ | |
| from django.core.urlresolvers import reverse | |
| from django.core.exceptions import ObjectDoesNotExist | |
| from django.contrib.auth import get_user_model | |
| from django.contrib.auth.models import User | |
| from django.utils.text import slugify |
| def get_weather(url="http://weather.yahooapis.com/forecastrss?w=12795483&u=f"): | |
| try: | |
| r = requests.get(url) | |
| # parse bytes into a text string | |
| text = r.content.decode("utf-8") | |
| #convert xml text to OrderedDict | |
| doc = xmltodict.parse(text) | |
| # item contains all the main temp info | |
| title = doc['rss']['channel']['title'] | |
| condition = doc['rss']['channel']['item']['yweather:condition'] |
| ### Docker Commands ### | |
| FROM ubuntu:trusty | |
| RUN apt-get update | |
| RUN DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential git python libpq-dev python-dev python-setuptools nginx supervisor | |
| RUN DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql postgresql-contrib | |
| RUN easy_install pip | |
| RUN pip install django==1.7.7 pyscopg2 uwsgi |
| ''' | |
| To convert zipcodes | |
| ------------------- | |
| From the output on: http://www.freemaptools.com/find-zip-codes-inside-radius.htm | |
| to a list of strings to use as a filter in SQL. | |
| Change data initially in this format: | |
| 1111,2222,3333 | |
| To this format: |
| #pip | |
| pip install redis | |
| pip install celery[redis] | |
| pip install django-celery | |
| # redis server | |
| # download here | |
| http://download.redis.io/redis-stable.tar.gz | |
| # follow install instructions here | |
| http://redis.io/topics/quickstart |
| import requests | |
| import xmltodict | |
| def get_weather(url="http://weather.yahooapis.com/forecastrss?w=12795483&u=f"): | |
| """ | |
| Get the current weather for Las Vegas using Yahoo!'s Weather API | |
| """ | |
| try: | |
| r = requests.get(url) | |
| # parse bytes into a text string |
| # ---------------------------- None View Helper Functions ------------------------------------ | |
| # Place to save image upload file | |
| def handle_uploaded_file(f): | |
| with open(content_file_name(f), 'wb+') as destination: | |
| for chunk in f.chunks(): | |
| destination.write(chunk) | |
| # Attempt Imagefield | |
| def content_file_name(instance, filename): |
| I currently use Postgres and a Mac for my Django Dev environment. However, when I first started I was using a Windows machine with MySQL. When I looked through my notes just now, it was pretty easy to set up. (I didn't use xampp however). What I installed was: | |
| 1. MySQL workbench: http://dev.mysql.com/downloads/workbench/ | |
| 2. MySQL-python connector - I used pip install for this. So if you have "pip" then it's just: | |
| pip install mysql-python | |
| 3. And, this is what my database settings looked like in my settings.py: | |
| DATABASES = { |
| from django.db import models | |
| from django.core.exceptions import ValidationError | |
| def validate_length(value): | |
| if len(value) != 5: | |
| raise ValidationError('%s is not five digits.' % value) | |
| class MyModel(models.Model): |