Home >  > 15行代码运行django

15行代码运行django

0

1.清爽版本

import sys

from django.conf import settings
from django.conf.urls import url
from django.http import HttpResponse
from django.core.management import execute_from_command_line

settings.configure(
        DEBUG = True, # 调试状态
        SECRET_KEY = 'iamasecretkeyhahahaha', # 默认的session需要的key,也为了CSRF
        ROOT_URLCONF = sys.modules[__name__], # url根目录的配置
    )

def home(request):
    return HttpResponse('a mini django website')  # 主页

urlpatterns = [
        url(r'^$', home), # 元组类型,默认请求发送到home函数
    ]

# 启动程序
if __name__ == "__main__":
    execute_from_command_line(sys.argv)

然后执行:python tes.py runserver

结果:

参考:
https://blog.csdn.net/dreamhua927/article/details/52461764

暧昧帖

本文暂无标签

发表评论

*

*