Search code examples
pythonwindowsdjangoapache2django-wsgi

How to host Django1.3.1 in Apache2.2?


I am Using python 2.7.2,Django 1.3.1, Apache 2.2.22 on WindowsXP(win32). By the documentation i found here i did the step by step, but when the directory section is given

   `Alias /media/ C:/Programs/TestDjango/mysite/media/
    <Directory C:/Programs/TestDjango/mysite/media/>
    Order deny,allow
    Allow from all
    </Directory>
    WSGIScriptAlias / C:/Programs/TestDjango/mysite/apache/django.wsgi
    <Directory C:/Programs/TestDjango/mysite/apache>
    Order deny,allow
    Allow from all
    </Directory>`

and restarted the Apache, On opening localhost/mysite i get a Microsoft Visual C++ Library runtime error, and the Apache error log shows "Caught ImproperlyConfigured while rendering: Error loading pyodbc module: DLL load failed: A dynamic link library (DLL) initialization routine failed."....My Django app run in WAMP but wish to know where did i go wrong using Apache2.2.22 alone. Followed many Django documentation but still the same, Please to help me find where did i go wrong. thanks

(identation was fixed by guettli)


Solution

  • I got it solved, it was the version problem, as i worked with Apache 2.2.21 instead of Apache 2.2.22, its working. i followed the step in this link.

    Install Python 2.7.2, Django 1.3.1 and Apache2.2.21 Install the modwsgi module.

    The module file will be named something like mod_wsgi-win32-ap22py26-2.6.so get mod_wsgi.

    Copy it to the modules directory of the Apache installation. E.g., C:/Program Files/Apache Software Foundation/Apache2.2/modules.

    Rename it to mod_wsgi.so. Right click--> properties click Unblock and apply

    Open Apache's http.conf file.

    Add the line LoadModule wsgi_module modules/mod_wsgi.so before all the other LoadModule entries.

    Configure Apache for your Django project by adding the following to end of http.conf:

    # Static content
        Alias /media/ C:/Programs/TestDjango/mysite/media/
    
        <Directory C:/Programs/TestDjango/mysite/media/>
        Order deny,allow
        Allow from all
        </Directory>
    
    # Django dynamic content
    
        WSGIScriptAlias / C:/Programs/TestDjango/mysite/apache/django.wsgi
    
        <Directory C:/Programs/TestDjango/mysite/apache>
        Order deny,allow
        Allow from all
        </Directory>`
    

    Where icardtest is the Django project root. The paths below icardtest will be specific to your project. This configuration serves all static media via the URL space /media/ and all the rest via WSGI and Django. Create a file django.wsgi and add the following to it:

          ` import os
            import sys
    
            sys.path.append('C:/Programs/TestDjango')
            os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
    
            import django.core.handlers.wsgi
            application = django.core.handlers.wsgi.WSGIHandler()`
    

    Restart Apache.