from django.http import HttpResponse
from django.conf.urls import url
from django.conf import settings
import sys settings.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 HttpResponse
from django.conf.urls import url
from django.conf import settings
from django.core.wsgi import get_wsgi_application
import sys
import os DEBUG = 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 settings
from django.http import HttpResponse
from django.conf.urls import url setting = {
'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

轻量级django 一-LMLPHP

轻量级django 一-LMLPHP

04-27 18:08