Deploy Django on Apache?

前端 未结 3 1054
醉梦人生
醉梦人生 2021-01-28 15:02

I create project using Django 1.8. now ,I want deploy it to server.when I run this command in Ubuntu every thing working find.

python manage.py runserver
         


        
相关标签:
3条回答
  • 2021-01-28 15:13

    finally I could successfully deploy my project.I enabled Apache this module early.

    refer this link

    --------------this is my virtual host file----------------------------------

    WSGIPythonPath /home/umayanga/Desktop/view_site/serialKey_gen_site:/home/umayanga/Desktop/view_site/serialKey_gen_site/myvenv/lib/python3.4/site$
    
    <VirtualHost *:80>
        ServerAdmin admin@key.com
        ServerName key.com
        ServerAlias www.key.com
    
        Alias /templates/ /home/umayanga/Desktop/view_site/serialKey_gen_site/templates/
        Alias /static/ /home/umayanga/Desktop/view_site/serialKey_gen_site/static/
    
    
        <Directory "/home/umayanga/Desktop/view_site/serialKey_gen_site/static">
               Require all granted
        </Directory>
    
        <Directory "/home/umayanga/Desktop/view_site/serialKey_gen_site/templates">
               Require all granted
        </Directory>
    
        WSGIScriptAlias / /home/umayanga/Desktop/view_site/serialKey_gen_site/mysite/wsgi.py
    
        <Directory "/home/umayanga/Desktop/view_site/serialKey_gen_site/mysite">
            Options Indexes FollowSymLinks
            AllowOverride all
            Require all granted
            <Files wsgi.py>
                   Require all granted
            </Files>
        </Directory>
    
    </VirtualHost>
    

    -----------------wsgi.py---------------------------------------

    """
    WSGI config for mysite project.
    
    It exposes the WSGI callable as a module-level variable named ``application``.
    
    For more information on this file, see
    https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
    """
    
    import os
    
    from django.core.wsgi import get_wsgi_application
    
    
    
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
    
    application = get_wsgi_application()
    

    I think this will be help to other Django developers.Thank you all developers those who help me.

    0 讨论(0)
  • 2021-01-28 15:22

    As I said in the comments, you're not doing anything to add your project to the PYTHONPATH so that the WSGI app can actually find it.

    It seems from your directory structure that you're using a virtualenv; you need to activate that either within the .wsgi file or in the Apache configuration itself. The Django docs recommend the latter.

    0 讨论(0)
  • 2021-01-28 15:32

    In your wsgi.py try changing

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
    

    to

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
    

    Since both files are in the same directory/module.

    0 讨论(0)
提交回复
热议问题