Django应用程序不可见 [英] Django application not visible

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

问题描述

我正在尝试使用 mod_wsgi Apache 在<$ c上部署Django应用程序$ c> Ubuntu 12.04 虚拟机。我一直在关注几个教程,特别是 Ayman Farhat博客 ,此优秀的YouTube视频,当然还有官方的Django文档

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

这是一个我在这里发布的早期问题想知道为什么我的Django调查在上传到/ var / www /(blush!)时并不简单,我一直在研究 mod_wsgi 根据答案。

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.

我不知道我失踪了什么阶段。该项目能够通过 python manage.py runserver 在服务器上启动,没有错误。我也运行 python manage.py collectstatic ,没有错误。

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.

然后我用

sudo service apache2 restart

然而,当我浏览网址 http://phaedrus.scss.tcd.ie/ bias_experiment / surveythree / 我期望看到调查没有什么。我只是看到标准的404错误。

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.

我真的不知道我下一步要做什么或为什么这不工作。

I am really not sure what I have to do next or why this is not working.

下面是我的设置和我迄今为止所尝试过的。

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

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

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


  • 调查(我的工作项目)

  • 民意调查(我正在关注的教程)

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

我的项目结构

My Project Structure

我的虚拟主机位于 / 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 >

我的WSGI文件位于 / 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()    

我的URL patt erns 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])),   
)


推荐答案

您要浏览的地址与您的Apache配置中的ServerName或ServerAlias指令,因此virtualhost将不知道对该请求做出响应。

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.

请注意,ServerAlias应与ServerName类似 - 主机名,不是一个URL,没有http前缀或路径。另外请注意,如果您需要该虚拟主机来响应许多主机名,则可以为ServerAlias提供多个值。

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.

如果您希望在/ bias_experiment下面提供Django应用程序,那么应该作为WSGIScriptAlias的一部分。

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

所以应该是:

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

此外,我对您的代码的位置感到困惑。是/ var / www / ...还是/ home / whoever / var / www?您的wsgi文件指的是后者,但Apache conf具有前者。

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.

接下来,virtualenv应该处理所有Python路径的设置。因此,由于您正在运行激活脚本,您可以删除修改sys.path和site.addsitedir的行。虽然您可能需要保留添加 src 目录的目录。

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.

另一个问题是您的DJANGO_SETTINGS_MODULE。它应该是一个Python模块,而不是一个文件路径 - 实际上你是两者之间的交叉。由于 src 在Python路径上,您可以将其设置为bias_experiment.settings。

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应用程序不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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