Django应用程序不visable。 [英] Django application not visable.

查看:213
本文介绍了Django应用程序不visable。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用的mod_wsgi 的Apache 在<$ C部署首次Django应用程序$ C>的Ubuntu 12.04 VM。我一直在以下几个教程,特别是艾曼Farhat的博客,这优秀的YouTube视频的,当然官方的Django文档

这是继一<一href=\"http://stackoverflow.com/questions/23874951/uploading-python-application-for-the-first-time-urlconfig-urls-not-working\">earlier问题我张贴在这里奇怪,为什么我的Django的调查并没有简单地工作,当我上传它在/ var / WWW /(脸红!)我后来一直在寻找到的mod_wsgi 按答案。

我不知道我错过了什么阶段。该项目通过蟒蛇manage.py的runserver 能够启动服务器上没有任何错误。我也跑了蟒蛇manage.py collectstatic 没有任何错误。

然后,我重新启动Apache

  sudo的服务重新启动的Apache2

然而,当我去的网址 http://phaedrus.scss.tcd.ie/bias_experiment / surveythree / ,我希望看到调查无所不有。我刚看到标准的404错误。

在此任何帮助将是巨大的AP preciated。我真的不知道我有什么下一步该怎么做,或者为什么这是行不通的。感谢您的帮助提前。

下面是我的设置和我所到目前为止已经试过。

请注意:我在Pydev的创建Bias_Experiment Django项目。它包含了一个的src 文件夹中的三个应用程序。


  • 调查(我的工作的项目)

  • 民意调查(一个教程中,我被下)

  • bias_experiment(根与我的设置应用程序文件等)

我的项目结构

我的虚拟主机位于的/ etc / apache2的/网站的可用/ bia​​s_experiment

 &LT;虚拟主机*:80&GT;
的ServerAdmin admin@email.com
服务器名kdeg-vm-18.scss.tcd.ie
ServerAlias​​ http://collegeserver.ie/bias_experiment
WSGIScriptAlias​​在/ var / WWW / bia​​s_experiment / src目录/ bia​​s_experiment / index.wsgi别名/静态/的/ var / WWW / bia​​s_experiment / src目录/ bia​​s_experiment /静态/
&LT;位置/静态/&GT;
    选项​​-Indexes
&LT; /地点&gt;
&LT; /虚拟主机&GT;

我的WSGI文件位于 /var/www/bias_experiment/src/bias_experiment/index.wsgi

 导入OS
进口SYS
导入站点#添加所选的virtualenv一起工作的站点包
site.addsitedir(〜/无功/网络/ bia​​s_experiment / lib中/ python2.7 / site-packages中)#添加应用程序的目录添加到PYTHONPATH
sys.path.append('/无功/网络/ bia​​s_experiment')
sys.path.append('/无功/网络/ bia​​s_experiment / src目录/ bia​​s_experiment')os.environ ['DJANGO_SETTINGS_MODULE'] ='bias_experiment / src目录/ bia​​s_experiment.settings#激活您的虚拟ENV
activate_env = os.path.expanduser(〜/无功/网络/ bia​​s_experiment /斌/ activate_this.py)
的execfile(activate_env,字典(__ __文件= activate_env))进口django.core.handlers.wsgi
应用= django.core.handlers.wsgi.WSGIHandler()

我的URL模式 bias_experiment / src目录/ bia​​s_experiment / urls.py

  URL模式=模式('',
    URL(R'^民调/',包括(polls.urls',命名空间=民意调查)),
    URL(R'^管理员/',包括:(admin.site.urls))
    URL(R'^ surveythree / $',SurveyWizard.as_view([SurveyForm1,SurveyForm2,SurveyForm3,SurveyForm4,SurveyForm5]))


解决方案

您在您的浏览器不匹配,无论是在Apache配置中的ServerName或ServerAlias​​指令要去的地址,所以虚拟主机将不知道回应该请求。

注意ServerAlias​​应该类似于服务器名 - 主机名,而不是一个URL,不包含http preFIX或路径。另外请注意,你可以有多个值ServerAlias​​如果你需要一个虚拟主机对主机名很多回应。

如果您希望Django应用程序送达底下/ bia​​s_experiment,这应该是WSGIScriptAlias​​的一部分。

因此​​,它应该是:

  ServerAlias​​ phaedrus.scss.tcd.ie
WSGIScriptAlias​​ / bia​​s_experiment /var/www/bias_experiment/src/bias_experiment/index.wsgi

此外,我感到困惑的code的位置。它是在/ var /网络/ ...或/家庭/谁在/ var / WWW?您WSGI文件指的是后者,但在Apache的conf有前者。

接下来的virtualenv应该采取设置所有的Python路径的照顾。如此以来,正在运行的脚本激活,您可以删除修改的sys.path和site.addsitedir行。虽然你可能需要保持一个添加的src 目录。

另一个问题是与你的DJANGO_SETTINGS_MODULE。这应该是一个Python模块,而不是文件路径 - 其实你有什么是他们两人之间的交叉。由于的src 是Python的道路上,你可以将其设置为bias_experiment.settings。

I am trying to deploy a Django application for the first time using mod_wsgi with Apache on a Ubuntu 12.04 VM. I have been following several tutorials, especially Ayman Farhat blog, this excellent YouTube video and of course the official Django Documentation

This follows an earlier question I posted here wondering why my Django survey did not simply work when I uploaded it to the /var/www/ (blush!) I have since been looking into mod_wsgi as per the answers.

I'm not sure what stage I am missing. The project is able to start on the server via python manage.py runserver with no errors. I have also ran python manage.py collectstatic with no errors.

I then restart Apache with

sudo service apache2 restart

However when I go the URL http://phaedrus.scss.tcd.ie/bias_experiment/surveythree/ where I expect to see the survey nothing is there. I just see the standard 404 error.

Any help in this would be hugely appreciated. I am really not sure what I have to do next or why this is not working. Thanks for your help in advance.

Below is my setup and what I have tried so far.

NOTE: I have a Bias_Experiment Django Project created in Pydev. It has three applications contained within an src folder.

  • survey (my working project)
  • polls (a tutorial i was following)
  • bias_experiment (the root application with my settings file etc)

My Project Structure

My virtual host located at /etc/apache2/sites-available/bias_experiment

<VirtualHost *:80>
ServerAdmin admin@email.com
ServerName kdeg-vm-18.scss.tcd.ie
ServerAlias http://collegeserver.ie/bias_experiment
WSGIScriptAlias / var/www/bias_experiment/src/bias_experiment/index.wsgi

Alias /static/ /var/www/bias_experiment/src/bias_experiment/static/
<Location "/static/">
    Options -Indexes
</Location >
</VirtualHost >

My WSGI file located at /var/www/bias_experiment/src/bias_experiment/index.wsgi

import os
import sys
import site

# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('~/var/www/bias_experiment/lib/python2.7/site-packages')

# Add the app's directory to the PYTHONPATH
sys.path.append('/var/www/bias_experiment')
sys.path.append('/var/www/bias_experiment/src/bias_experiment')

os.environ['DJANGO_SETTINGS_MODULE'] = 'bias_experiment/src/bias_experiment.settings'

# Activate your virtual env
activate_env=os.path.expanduser("~/var/www/bias_experiment/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()    

My URL patterns from bias_experiment/src/bias_experiment/urls.py

urlpatterns = patterns('',
    url(r'^polls/', include('polls.urls', namespace="polls")),
    url(r'^admin/', include(admin.site.urls)),        
    url(r'^surveythree/$', SurveyWizard.as_view([SurveyForm1, SurveyForm2, SurveyForm3, SurveyForm4, SurveyForm5])),   
)

解决方案

The address you are going to in your browser does not match either the ServerName or ServerAlias directives in your Apache configuration, so the virtualhost won't know to respond to that request.

Note that ServerAlias should be similar to ServerName - a hostname, not a URL, without http prefix or path. Also note you can have multiple values for ServerAlias if you need that virtualhost to respond to many hostnames.

If you want the Django app to be served underneath /bias_experiment, that should be part of the WSGIScriptAlias.

So it should be:

ServerAlias phaedrus.scss.tcd.ie
WSGIScriptAlias /bias_experiment /var/www/bias_experiment/src/bias_experiment/index.wsgi

Also I'm confused about the locations of your code. Is it in /var/www/... or /home/whoever/var/www? Your wsgi file refers to the latter, but the Apache conf has the former.

Next, virtualenv is supposed to take care of setting all the Python paths. So since you are running the activate script, you can remove the lines that modify sys.path and site.addsitedir. Although you might need to keep the one that adds the src directory.

Another problem is with your DJANGO_SETTINGS_MODULE. It should be a Python module, not a file path - actually what you have is a cross between them both. Since src is on the Python path, you can just set this to 'bias_experiment.settings'.

这篇关于Django应用程序不visable。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆