zoukankan      html  css  js  c++  java
  • 轻量级django 一

    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

  • 相关阅读:
    对bootstrap不同版本的总结
    对于前后端分离的理解
    css3笔记
    Dom
    js菜单
    css兼容问题 ie6,7
    html知识
    前端基础知识
    前端要注意的代码规范
    bootstrap常见类的总结
  • 原文地址:https://www.cnblogs.com/Erick-L/p/7644869.html
Copyright © 2011-2022 走看看