How do I write a single-file Django application?

后端 未结 11 1869
余生分开走
余生分开走 2020-12-14 19:29

I want to write a very small Django application in a single file, requiring all the appropriate modules and stuff, and then be able to run that as a normal Python script, li

11条回答
  •  粉色の甜心
    2020-12-14 20:01

    Getting started with Django can be pretty easy too. Here's a 10-line single-file Django webapp:

    import os
    from django.conf.urls.defaults import patterns
    from django.http import HttpResponse
    filepath, extension = os.path.splitext(__file__)
    ROOT_URLCONF = os.path.basename(filepath)
    
    def yoohoo(request):
        return HttpResponse('Yoohoo!')
    
    urlpatterns = patterns('', (r'^hello/$', yoohoo))
    

    Check out my blog post Minimal Django for details.

提交回复
热议问题