Host Django with XAMPP on Windows

前端 未结 5 815
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-30 11:59

Can I run a Django (Python framework) base site with XAMPP on Windows? Please guide me.

5条回答
  •  臣服心动
    2021-01-30 12:39

    The running django on xampp can be divided into two steps.

    • Step 1 : install wsgi and check if everything is OK
      • follow the steps in the answer of this post - Setting Python Path in Windows XAMPP using WSGI
    • Step 2 : install and run django
      • run easy_install django to install django on PC
      • test django
      • follow the example in "http://docs.djangoproject.com/en/dev/intro/tutorial01/"
      • I assume the generated django code is in C:\xampp\htdocs\django\mysite
      • Make the mysite.wsgi in C:\xampp\htdocs\wsgi\scripts

    mysight.wsgi

    import os
    import sys    
    mysite = r'C:/xampp/htdocs/django'
    if mysite not in sys.path:sys.path.insert(0,mysite)
    mysite = r'C:/xampp/htdocs/django/mysite'
    if mysite not in sys.path:sys.path.insert(0,mysite)
    
    os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
    
    import django.core.handlers.wsgi
    application = django.core.handlers.wsgi.WSGIHandler()
    

    • You can add WSGIScriptAlias /mysite "C:/xampp/htdocs/wsgi/scripts/mysite.wsgi" in wsgi.conf to run http://YOURSITE/mysite, or you can just run http://YOURSITE/wsgi/mysite.wsgi
    • Relaunch apache if necessary.

提交回复
热议问题