Reputation: 21
I have a Django application that I am trying to host using mod_wsgi and Apache webserver on Debain Linux.
The code works fine on my local machine and the Live server using the Django development webserver. I can successfully browse to 127.0.0.1:8000/index
When I try to run via Apache, Here is the Error I receive (Apache error log)
[Fri Jul 04 10:46:17 2014] [error] [client ] File does not exist: /var/www/mydomain.com/htdocs/DataAnalysis/DataAnalysisSite/wsgi.py/index
I have read and tried all the combinations in the following articles - webpython.codepoint.net/wsgi_tutorial - docs.djangoproject.com/en/dev/topics/install/ - library.linode.com/frameworks/django-apache-mod-wsgi/ubuntu-10.04-lucid - stackoverflow.com/questions/11380214/why-doesnt-apache-display-404-errors-with-django-and-mod-wsgi - blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html
Here is my Directory Structure
.
DataAnalysis
├── Application
│ ├── admin.py
│ ├── admin.pyc
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── models.py
│ ├── models.pyc
│ ├── tests.py
│ ├── views.py
│ └── views.pyc
├── DataAnalysisSite
│ ├── Alt.pkl
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── settings.py
│ ├── settings.pyc
│ ├── urls.py
│ ├── urls.pyc
│ ├── Wann.pkl
│ ├── wsgi.py
│ └── wsgi.pyc
├── manage.py
├── templates
│ └── search_form.html
└── wsgi.py
Here is my apache config file :
<Directory /var/www/mydomain.com/htdocs>
Options ExecCGI Indexes
Order deny,allow
Allow from all
AddHandler /var/www/mydomain.com/htdocs/DataAnalysis/DataAnalysisSite/wsgi.py .py
</Directory>
<VirtualHost xx.xxx.xxx.xx:80>
ServerName mydomain.com
ServerAdmin [email protected]
ErrorLog "/var/log/apache2/mydomain.com-error.log"
CustomLog "/var/log/apache2/dmydomain.com-access.log" combined
WSGIScriptAlias / /var/www/mydomain.com/htdocs/DataAnalysis/DataAnalysisSite/wsgi.py
</VirtualHost>
Here is my Wsgi.py file :
import sys
import site
import os
import django.core.handlers.wsgi
# we add currently directory to path and change to it
pwd = os.path.dirname(os.path.abspath(__file__))
os.chdir(pwd)
sys.path = [pwd] + sys.path
sys.path.insert(0, '/var/www/mydomain.com/htdocs/DataAnalysis')
sys.path.insert(1,'/var/www/mydomain.com/htdocs/DataAnalysis/DataAnalysisSite')
sys.path.append('/var/www/mydomain.com/htdocs/DataAnalysis')
sys.path.append('/var/www/mydomain.com/htdocs/DataAnalysis/DataAnalysisSite')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "DataAnalysisSite.settings")
#from django.core.wsgi import get_wsgi_application
#application = get_wsgi_application()
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Here is my urls.py file:
from django.conf.urls import patterns, include, url
from Application import views
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'form_test.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^index/$', views.index),
url(r'^search-form/$', views.search_form),
url(r'^search/$', views.search),
)
I am using pycharm and views.py is in application folder along with unit.py,admin.py models.py and test.py.
Here is my views.py:
from django.shortcuts import render
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from sklearn.naive_bayes import GaussianNB
from sklearn import cross_validation
from sklearn.feature_extraction import DictVectorizer
from sklearn.externals import joblib
import os
import csv
@csrf_exempt
def index(request):
return HttpResponse('welcome to python django')
Why can my wsgi file not find anything in views.py?
Is there any configuration error? Any help is really appriciated!
Best
Upvotes: 0
Views: 1727
Reputation: 599778
The error message tells you exactly what is going on: there is nothing to match the root URL, /
. That should be obvious from your urls.py: you have patterns for "admin", "index", "search-form" and "search", but nothing for "".
However you should have diagnosed this before deploying. When you ran it on your local machine with the development server, what happened when you went to localhost:8000/
? You would have seen exactly the same error, and you would not then have thought it had anything to do with your Apache configuration.
Upvotes: 1