Set Up Django Development Environment (local + github + pythonanywhere)

This is a guide/note for set up django web development environment. The main idea is to test the web app locally and push it to github and launch it to pythonanywhere.

Part 1 – Local Environment in Windows (Windows Power Shell)
1.1 Set up virtual environment for python
virtualenv C:\dir_to\env_name --python=C:\python34\python.exe
1.2 Activate virtual environment
C:\dir_to\env_name\Scripts\activate #If script cannot run: Set-ExecutionPolicy RemoteSigned
1.3 Update pip
python -m pip install --upgrade pip
1.4 Install django in virtual environment
pip install django==1.11
1.5 Create django project
django-admin startproject mysite
1.6 Create django app
python manage.py startapp appname
1.7 Edit django project setting.py: add appname to INSTALLED_APPS list
1.8 Edit django project urls.py:
from django.conf.urls import url, include
urlpatterns = [url(r'^$', include('myapp.urls')),]

1.9 Create urls.py in app folder
from django.conf.urls import url, include
from . import views
urlpatterns = [url(r'^$', views.index, name='index'),]

Part 2 – Link local django app to github respo
2.1 Create respo in github online
2.2 Get the respo link (example: https://github.com/username/appname.git)
2.3 Create .git in django app folder: git init
2.4 Add all files to git: git add --all .
2.5 Commit changes: git comment -a -m "commit notes"
2.6 Set up remote address: git remote add origin github_httpslink
2.7 Push local files to github: git push origin master

Part 3 – Set up pythonanywhere.com and link to github
3.1 Create virtual environment
$ mkvirtualenv space_name --python=/usr/bin/python3.4
3.2 Install django
$ pip install django==1.11
3.3 Create django project
$ django-admin startproject mysite
3.4 Create django app (only create the folder in the project dir)
3.5 Edit project setting.py
ALLOWED_HOSTS = ['.pythonanywhere.com']
3.6 Migrate the change: $ python manage.py migrate
3.7 Edit django project setting.py: add appname to INSTALLED_APPS list
3.8 Edit project urls.py
from django.conf.urls import url, include
urlpatterns = [url(r'^$', include('myapp.urls')),]

3.9 Create web in the tab: manual config
3.10 Edit the wsgi file: find the django section uncomment the code
3.11 Create .git in django app folder: git init
3.12 Set up remote address: git remote add origin github_httpslink
3.13 Pull from github: git pull origin master

First time config:
git config --global user.name "Your Name"
git config --global user.email you@example.com

# git conflect window
hit esc, type in “:wq”, hit enter

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s