Created
February 28, 2014 04:21
-
-
Save etng/9265193 to your computer and use it in GitHub Desktop.
Init a django project
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
pip install virtualenvwrapper | |
source /usr/local/bin/virtualenvwrapper.sh | |
cat >> ~/.bashrc << “END” | |
export WORKON_HOME=$HOME/.virtualenvs | |
source /usr/local/bin/virtualenvwrapper.sh | |
END | |
mkvirtualenv myenv | |
workon myenv | |
pip install django jieba pypinyin requests | |
pip install django-debug-toolbar South django-model-utils django-extensions django-braces django-forms-bootstrap django-floppyforms django-admin-honeypot django-secure django-htmlmin django-pipeline | |
pip install Sphinx Pillow | |
export PROJECT_NAME="hellword" | |
cd ~/projects | |
mkdir ${PROJECT_NAME} | |
cd ${PROJECT_NAME} | |
mkdir requirements | |
pip freeze > requirements/_base.txt | |
cat > requirements/local.txt << 'END' | |
-r _base.txt # includes the _base.txt requirements file | |
END | |
cat > requirements/production.txt << 'END' | |
-r _base.txt # includes the _base.txt requirements file | |
END | |
touch .gitignore | |
mkdir docs | |
touch docs/deployment.rst | |
touch docs/installation.rst | |
touch docs/architecture.rst | |
touch docs/deployment.rst | |
touch README.rst | |
django-admin.py startproject ${PROJECT_NAME} | |
cd ${PROJECT_NAME} | |
mkdir {static,media,templates} | |
mkdir ${PROJECT_NAME}/settings | |
touch ${PROJECT_NAME}/settings/__init__.py | |
cat > ${PROJECT_NAME}/settings/base.py << END | |
import os | |
from django.core.exceptions import ImproperlyConfigured | |
def get_env_variable(var_name): | |
try: | |
return os.environ[var_name] | |
except KeyError: | |
error_msg = "Set the %s env variable" % var_name | |
raise ImproperlyConfigured(error_msg) | |
from os.path import join, abspath, dirname | |
here = lambda *x: join(abspath(dirname(__file__)), *x) | |
PROJECT_ROOT = here("..", "..") | |
root = lambda *x: join(abspath(PROJECT_ROOT), *x) | |
END | |
cat ${PROJECT_NAME}/settings.py >> ${PROJECT_NAME}/settings/base.py | |
rm -f ${PROJECT_NAME}/settings.py | |
cat > ${PROJECT_NAME}/settings/local.py << 'END' | |
from .base import * | |
DEBUG=True | |
TEMPLATE_DEBUG=True | |
INSTALLED_APPS += ( | |
'debug_toolbar', | |
) | |
INTERNAL_IPS = ('127.0.0.1',) | |
MIDDLEWARE_CLASSES += ( | |
'debug_toolbar.middleware.DebugToolbarMiddleware', | |
) | |
END | |
cat > ${PROJECT_NAME}/settings/production.py << 'END' | |
from .base import * | |
DEBUG=False | |
TEMPLATE_DEBUG=False | |
END | |
export DJANGO_ROOT=`python -c 'import django;print django.__path__[0];'` | |
cp -fr ${DJANGO_ROOT}/contrib/admin/static/admin static/ | |
cp -fr ${DJANGO_ROOT}/contrib/admin/templates/* templates/ | |
export DJANGO_SETTINGS_MODULE=${PROJECT_NAME}.settings.local | |
django-admin.py syncdb | |
django-admin.py runserver 0.0.0.0:8972 | |
cd ../ >/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment