Steps
Log into glenn.osc.edu
, then:
- Setup new django project with passenger
- Add hello world view and route
- Work around the root directory config defect
1. Setup new django project with passenger
Make sure you add the .htaccess file as described at the bottom of this section before accessing the app through https://apps.awesim.org/devapps
Log into glenn.osc.edu
Load python module and move into awesim_dev directory:
-bash-3.2$ cd ~/awesim_dev
-bash-3.2$ module load python-2.7.1
Start a new project to work with passenger:
-bash-3.2$ /usr/local/python/2.7.1/lib/python2.7/site-packages/django/bin/django-admin.py startproject hello
-bash-3.2$ mv hello django1
-bash-3.2$ cd django1
-bash-3.2$ mkdir {public,tmp}
-bash-3.2$ cp hello/wsgi.py passenger_wsgi.py
Add 2 lines above os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hellodj.settings")
in passenger_wsgi.py:
import sys
sys.path.append(os.path.join(os.environ["HOME"], 'awesim_dev/django1'))
After these steps are done you will have a directory ~/awesim_dev/django1 with these contents:
-bash-3.2$ ls ~/awesim_dev/django1 -1
hello
manage.py
passenger_wsgi.py
public
tmp
The existence of passenger_wsgi.py
, public
and tmp
are what make this a Passenger app.
Add .htaccess file
Finally, add a .htaccess file to:
- set development mode on passenger: WSGI and Rack apps in development mode
- ensure restarting the passenger app works via
touch tmp/restart.txt
: htaccess modification for restarting passenger apps
2. Add hello world view and route
Add hello/views.py for hello world:
-bash-3.2$ cat hello/views.py
from django.http import HttpResponse
def home(request):
return HttpResponse("<h1>Home!</h1>");
def hello(request):
return HttpResponse("<h1>Hello!</h1>");
Update url conf patterns in hello/urls.py with these two lines:
url(r'^$', 'hello.views.home'),
url(r'^hello', 'hello.views.hello')
so you have
-bash-3.2$ cat hello/urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^$', 'hello.views.home'),
url(r'^hello', 'hello.views.hello')
)
If you access https://websvcs02.osc.edu/awesim_dev/django1/ you get "Service Temporarily Unavailable" but if you access https://websvcs02.osc.edu/awesim_dev/django1/hello you get "Hello".
* https://websvcs02.osc.edu is not a permanent address - the domain for development PUAs may change in the future
3. Work around the root directory config defect
Currently if you go to http://websvcs02.osc.edu/django1/ instead of seeing the home view you see "Service Temporarily Unavailable". We have a problem with the configuration that is currently preventing this. Until this is fixed, place an index.html file that will redirect to another route:
Create this page in public/, making the url value to the desired starting route:
-bash-3.2$ cat public/index.html
<html>
<head>
<meta http-equiv="REFRESH" content="0;url=hello"/>
<title></title>
</head>
<body>
</body>
</html>
Now when your browser requests http://websvcs02.osc.edu/django1/ it will be redirected to http://websvcs02.osc.edu/django1/hello
TODO
- Find a solution to namespacing the app
- Replace rails terminology (route) with django terminology (is it url pattern?)
- Offer a hello world example users can refer to
- Create a script to automate this initial setup for a new django project