Host Django with XAMPP on Windows

前端 未结 5 807
爱一瞬间的悲伤
爱一瞬间的悲伤 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:24

    You may want to checkout DjangoStack. It is similar to XAMPP in that is free, multiplatform and self-contained but it comes with Django installed by default.

    0 讨论(0)
  • 2021-01-30 12:30

    XAMPP for windows contains: Apache, MySQL, PHP + PEAR, Perl, mod_php, mod_perl, mod_ssl, OpenSSL, phpMyAdmin, Webalizer, Mercury Mail Transport System for Win32 and NetWare Systems v3.32, Ming, JpGraph, FileZilla FTP Server, mcrypt, eAccelerator, SQLite, and WEB-DAV + mod_auth_mysql.

    There are two requirements to run django missing:

    • Python
    • mod_wsgi

    So, NO, you can't run django with XAMPP alone. You need to install additional software.

    However running django is very easy. If you just want to develop an application, you only need python and django. Django itself includes an internal web server that can be used for development.

    If you want to use django on windows for a production server, you don't even need the apache web server. You could install just:

    • Python
    • cherrypy

    That's enough to have a good django production server up and running, since cherrypy's web server is written in python and is pretty good to serve django (or any other wsgi-compatible) applications. If you're not using apache for anything else I think this setup is actually better and easier. There are other webservers you could use instead of cherrypy. But if you really want to use apache, you also need mod_wsgi.

    0 讨论(0)
  • 2021-01-30 12:30

    I'm not sure what you want, so this may not be a proper answer.

    If you just want to run a development server (for yourself), it would be easier to use a web server provided by Django framework. Read more about that in the book: http://www.djangobook.com/en/2.0/chapter02/

    0 讨论(0)
  • 2021-01-30 12:33

    Yes, you can, but first you have to install Python and mod_python. See this FAQ.

    However for development purposes, it is far easier to use the built in Django development server. This will be much easier to use and setup to get you started.

    0 讨论(0)
  • 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.
    0 讨论(0)
提交回复
热议问题