狼爱上狸

我胡汉三又回来了

集合了manage.py,setting.py,view.py,urls.py于一声的Hello World.

安装好django后,建立一下hello.py文件:

import
os
import sys

from django.conf import settings

DEBUG = os.environ.get('DEBUG', 'on') == 'on'

SECRET_KEY = os.environ.get('SECRET_KEY', os.urandom(32))

ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', 'localhost').split(',')

settings.configure(
DEBUG=DEBUG,
SECRET_KEY=SECRET_KEY,
ALLOWED_HOSTS=ALLOWED_HOSTS,
ROOT_URLCONF=__name__,
MIDDLEWARE_CLASSES=(
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
),
)

from django.conf.urls import url
from django.core.wsgi import get_wsgi_application
from django.http import HttpResponse


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)

运行python hello.py runserver 0.0.0.0:8000看看效果

posted on 2018-10-24 19:19 狼爱上狸 阅读(167) 评论(0)  编辑  收藏 所属分类: Django