Last active
August 29, 2015 14:01
-
-
Save fraank/48fce2acd59c8dc16907 to your computer and use it in GitHub Desktop.
a pragmatic guide to start django to be productive from zero
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ============= | |
# Basic Setup | |
# ============= | |
# I guess you’ve Python, right? So here we go to install django | |
$ pip install Django==1.6.4 | |
# It should output the Version number you set above | |
$ python -c "import django; print(django.get_version())" | |
# Start A new Project | |
$ django-admin.py startproject mycoolproject | |
# => ok now you have an empty project | |
# you can rub it with | |
$ python manage.py runserver | |
# when you run the url 127.0.0.1 you should see a smart welcome screen | |
# if you run it on a vertial box you should start the server with this command | |
# to make the webserver listen to any address | |
$ python manage.py runserver 0.0.0.0:8000 | |
# ok what's next? We have a working server and that's fine for now. | |
# django seems to be strucurized in little apps, which handle for example one model | |
# so we create the first that stores information of images | |
# ( be sure you do this in the root-folder of your app ) | |
python manage.py startapp images | |
# ========================== | |
# Easy Package Management | |
# ========================== | |
# from ruby i loved bundler, which gives me the ability to install all denpendencies with one line of code | |
# pip can do aswell, we just have to create a requirements.txt, where we store each dependency in one line | |
# the file could look like this, to install django (already installed) and mongoengine: | |
django==1.6.4 | |
mongoengine | |
# after that we can install all dependencies | |
$ pip install -r requirements.txt | |
# ============= | |
# MongoDB | |
# ============= | |
# Because we are cool and we've already installed a mongomapper, we don't wanna use a relational database | |
# instead we use this mongo datastore to save all the informations we have for an image | |
# add this to your settings to connect to the database | |
# And the mongo-connection | |
import mongoengine | |
DATABASES = { | |
'default': { | |
'ENGINE': '', | |
}, | |
} | |
SESSION_ENGINE = 'mongoengine.django.sessions' # optional | |
_MONGODB_USER = 'admin' | |
_MONGODB_PASSWD = 'admin' | |
_MONGODB_HOST = '192.168.50.4' | |
_MONGODB_PORT = 27017 | |
_MONGODB_NAME = 'likewalk' | |
mongoengine.connect(_MONGODB_NAME, username=_MONGODB_USER, password=_MONGODB_PASSWD, host=_MONGODB_HOST, port=_MONGODB_PORT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment