Joseph Izang
Joseph Izang

Reputation: 755

wamp django apache error

I am trying to setup django python on wamp ( the latest). With all configurations done I get a 500 internal error. When I check my error logs I see that there is a syntax error and I compare with what I find from google and its the same. I have copied it here so please tell me what the problem is please. For background I am using Windows 7 64bit Professional with wamp 2.2 32bit. here are my configs:

LoadModule wsgi_module modules/mod_wsgi.so
    
WSGIScriptAlias / "d:/projects/testproject/django.wsgi"
[Directory D:/projects/testproject]
Order deny,allow
Allow from all
[/Directory]

This is my django.wsgi:


import os
import os.path
import sys
sys.path.append('d:/projects/') 
os.environ['DJANGO_SETTINGS_MODULE'] = 'testProject.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()


[Wed Mar 28 01:11:33 2012] [error] [client 127.0.0.1] mod_wsgi (pid=680, process='', application='localhost|'): Failed to parse WSGI script file 'D:/projects/testproject/django.wsgi'.
[Wed Mar 28 01:11:33 2012] [error] [client 127.0.0.1] mod_wsgi (pid=680): Exception occurred processing WSGI script 'D:/projects/testproject/django.wsgi'.
[Wed Mar 28 01:11:33 2012] [error] [client 127.0.0.1]   File "D:/projects/testproject/django.wsgi", line 2
[Wed Mar 28 01:11:33 2012] [error] [client 127.0.0.1]     sys.path.append('d:/projects/') os.environ['DJANGO_SETTINGS_MODULE'] = 'testproject.settings'
[Wed Mar 28 01:11:33 2012] [error] [client 127.0.0.1]                                      ^
[Wed Mar 28 01:11:33 2012] [error] [client 127.0.0.1] SyntaxError: invalid syntax
[Wed Mar 28 01:11:57 2012] [notice] Parent: Received shutdown signal -- Shutting down the server.

I am sure there is something I am missing. Please help.

EDIT:


[Wed Mar 28 12:39:11 2012] [error] [client 127.0.0.1] mod_wsgi (pid=3156, process='', application='localhost|'): Failed to parse WSGI script file 'D:/projects/testproject/django.wsgi'.
[Wed Mar 28 12:39:11 2012] [error] [client 127.0.0.1] mod_wsgi (pid=3156): Exception occurred processing WSGI script 'D:/projects/testproject/django.wsgi'.
[Wed Mar 28 12:39:11 2012] [error] [client 127.0.0.1]   File "D:/projects/testproject/django.wsgi", line 2
[Wed Mar 28 12:39:11 2012] [error] [client 127.0.0.1]     sys.path.append('d:/projects/') os.environ['DJANGO_SETTINGS_MODULE'] = 'testproject.settings'
[Wed Mar 28 12:39:11 2012] [error] [client 127.0.0.1]                                      ^
[Wed Mar 28 12:39:11 2012] [error] [client 127.0.0.1] SyntaxError: invalid syntax

In the error logs it puts a caret (^) under os.environ saying there is a syntax error. So I did what graham suggested and made sure of my line endings but still errors is all I get. Error 500 Internal Error.

Upvotes: 0

Views: 1128

Answers (2)

citmusa
citmusa

Reputation: 11

try in wsgi.py:

import os, sys
sys.path.append(os.sep.join(os.path.abspath(__file__).split(os.sep)[:-2]))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

and then in httpd.conf:

WSGIScriptAlias /test "d:\projects\testproject\testproject\wsgi.py"

Finally you should create an alias Alias /test/ "c:/projects/testproject/"

<Directory "c:/projects/testproject/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Order allow,deny
    Allow from all
</Directory>

And that's all. Now go to localhost/test

Upvotes: 1

Graham Dumpleton
Graham Dumpleton

Reputation: 58523

You likely have mixed line endings in the file. IOW, mixture of \r\n and \n, or maybe even \r. Line endings need to be consistent.

Upvotes: 1

Related Questions