from django.http import HttpResponsefrom django.conf.urls import urlfrom django.conf import settingsimport syssettings.configure( DEBUG = True, SECRET_KEY = "HAHA", ROOT_URLCONF = __name__, MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ), )def index(request): return HttpResponse("hello world")urlpatterns = ( url(r'^$',index), )if __name__ == '__main__': from django.core.management import execute_from_command_line execute_from_command_line(sys.argv)
完善后
from django.http import HttpResponsefrom django.conf.urls import urlfrom django.conf import settingsfrom django.core.wsgi import get_wsgi_applicationimport sysimport osDEBUG = os.environ.get('DEBUG','on') == 'on'SECRET_KEY = os.environ.get('SECRET_KEY','=3k+l%xeb=fp@04uci&wy&ca14*@7ebxsu*6jd_ym1t3k^w)v*')ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS','localhost').split(',')settings.configure( DEBUG = DEBUG, SECRET_KEY = SECRET_KEY, #ALLOWED_HOSTS = ALLOWED_HOSTS, ALLOWED_HOSTS= ALLOWED_HOSTS, ROOT_URLCONF = __name__, MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ), )def index(request): return HttpResponse("hello world")urlpatterns = ( url(r'^$',index), )application = get_wsgi_application()if __name__ == '__main__': from django.core.management import execute_from_command_line execute_from_command_line(sys.argv)
更轻量的django
from django.conf import settingsfrom django.http import HttpResponsefrom django.conf.urls import urlsetting = { 'DEBUG':True, 'ROOT_URLCONF':__name__}settings.configure(**setting)def home(request): return HttpResponse('hello world')urlpatterns = [url('^$',home,name='home')]if __name__ == '__main__': import sys from django.core.management import execute_from_command_line execute_from_command_line(sys.argv)
python test runserver