Rick Seymour

Django – In development – settings and views

This is a quick way for a Django site to display an “In Development” message. It is not designed to be “secure”, so make sure you have a disallow * in your robots.txt file to ensure urls aren’t guessable.

urls.py

Place at the top of urls.py (then include subsequent additions with “urlpatterns+=”)

if settings.DEVELOPERMODE:
	urlpatterns = patterns('views',
		url(settings.DEVELOPER_URL,'developer_set'),
		url(r'^$','developer_home',name='home'),
	)
else:
	urlpatterns = patterns('views',url(r'^$','home',name='home'),)

views.py

from django.conf import settings

def developer_home(request):
	if settings.DEVELOPER_COOKIE in request.COOKIES:
		user=request.user
		return render_to_response('home.htm',{
			'user':user,
		},context_instance=RequestContext(request))
	else:
		return render_to_response('developer_indevelopment.htm')

def developer_set(request):
	R=HttpResponse("Developer mode set <a href='/'>Home</a>")
	R.set_cookie(settings.DEVELOPER_COOKIE,1)
	return R

Settings.py

DEVELOPERMODE	=False
DEVELOPER_COOKIE='developer_set_123'
DEVELOPER_URL	=r'^'+DEVELOPER_COOKIE+'$'

try:
   from settings_production import *
except ImportError, e:
   pass

try:
   from settings_development import *
except ImportError, e:
   pass

settings_production.py

DEVELOPERMODE	=True

settings_development.py

DEVELOPERMODE	=False

developer_indevelopment.htm

Stylise in your own custom way, include this in your templates directory

Leave your Reply: