File does not exist error in django,mod_wsgi and apache configuration

故事扮演 提交于 2020-01-17 03:52:06

问题


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 webmaster@mydomain.com

    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


回答1:


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.



来源:https://stackoverflow.com/questions/24553444/file-does-not-exist-error-in-django-mod-wsgi-and-apache-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!