无法导入/无命名Django的错误与Apache模块 [英] Could not import/No module named Django Error with Apache

查看:271
本文介绍了无法导入/无命名Django的错误与Apache模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个概念证明小在本地机器上建立一个开发服务器上。现在我想将其移动到Django的生产服务器,我使用webfaction上。然而,现在我是从切换到Apache内置在Django的服务器我得到以下内容:

I had a small proof of concept set up on a development server on a local machine. I'm now trying to move it over to django on a production server, which I'm using webfaction for. However, now that I'm switched over to apache from the built in django server I get the following:

ViewDoesNotExist: Could not import orgDisplay.views. Error was: No module named orgDisplay.views

但是,当检查我的orgDisplay apps文件夹中有它view.py。我究竟做错了什么?我试着用Django的IRC室的建议添加以下到我的settings.py。

But when check my orgDisplay apps folder there is a view.py in it. What am I doing wrong? I've tried adding the following to my settings.py by suggestion of the django IRC room.

import sys
sys.path.append(r"/home/user/webapps/django_project/myproject/orgDisplay")

这是通向我的应用程序。

which is the path to my app.

如何甚至开始麻烦任何想法拍这个?

any ideas on how to even begin to trouble shoot this?

先谢谢了。

推荐答案

我假设你正在使用的mod_wsgi (这是由Django的作者推荐),而不是的mod_python 。这是你应该用你的sys.path方式:

I assume you're using mod_wsgi (which is recommended by Django authors), not mod_python. This is the way you should use your sys.path:

django.wsgi:

django.wsgi:

import os, sys
sys.path.append(r"/home/user/webapps/django_project/myproject/")
os.environ["DJANGO_SETTINGS_MODULE"] = "settings"

sys.stdout = sys.stderr # Prevent crashes upon print

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

urls.py:

urls.py:

from django.conf.urls.defaults import *
urlpatterns = (
   ("", include("orgDisplay.urls")),
   # ...
)

orgDisplay / urls.py:

orgDisplay/urls.py:

import views

urlpatterns = ( 
    (r'^some_view/$', views.some_view), # It is actually orgDisplay.views.some_view
    # many more records ...
)

这是一个坏主意项目目录自身添加到路径,因为你会得到多个项目之间的名称冲突。

It is a bad idea to add project dir itself to path since you're be getting name conflicts between multiple projects.

这篇关于无法导入/无命名Django的错误与Apache模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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