500 互联网服务器错误 error_log:TemplateSyntaxError: 渲染时捕获 ImportError: 没有名为friends 的模块

发布于 2024-11-06 01:36:50 字数 1636 浏览 2 评论 0原文

最近我在 Apache 上使用 django 和 mod_wsgi。

我是按照以下步骤在网页中找到的:

“我的应用程序在/mnt/www/,名称叫mysite,apache,并在mysite媒体目录中创建,然后执行以下操作:”

创建 apache_django_wsgi.conf 文件,如下:

Alias ​​/ site_media / / mnt / www / mysite / media /

<Directory /mnt/www/mysite/media>
Order allow, deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</ Directory>

Alias ​​/ media / / usr/local/lib/python2.5/site-packages/django/contrib/admin/media /

<Directory /usr/local/lib/python2.5/site-packages/django/contrib/admin/media>
Order allow, deny
Options Indexes
Allow from all
IndexOptions FancyIndexing  
</ Directory>

WSGIScriptAlias ​​/ / mnt / www / mysite / apache / django.wsgi

<Directory /mnt/www/mysite>
Order deny, allow 
Allow from all
</ Directory>

<Directory /mnt/www/mysite/apache>
Allow from all
</ Directory>

创建 django.wsgi 文件,如下:

import os, sys

# Calculate the path based on the location of the WSGI script.

apache_configuration = os.path.dirname (__file__)

project = os.path.dirname (apache_configuration)

workspace = os.path.dirname (project)

sys.path.append (workspace)

os.environ ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

os.environ ['PYTHON_EGG_CACHE'] = '/ tmp'

import django.core.handlers.wsgi

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

print>> sys.stderr, sys.path

我已按照这些步骤操作,但是当我通过浏览器在 Apache 下运行它时,出现 500 Internet 服务器错误。然后我检查 erro_log:它说:“TemplateSyntaxError:渲染时捕获导入错误:没有名为friends的模块”(friends 是我的模块之一的名称)

我的站点的路径是 /var/BigPrject/mysite

Recently I am using django and mod_wsgi on Apache.

I am follow the following steps found in a webpage:

"My application in / mnt / www /, the name of the called mysite, apache and created in the mysite media directory, and then do the following:"

create apache_django_wsgi.conf file, as follows:

Alias ​​/ site_media / / mnt / www / mysite / media /

<Directory /mnt/www/mysite/media>
Order allow, deny
Options Indexes
Allow from all
IndexOptions FancyIndexing
</ Directory>

Alias ​​/ media / / usr/local/lib/python2.5/site-packages/django/contrib/admin/media /

<Directory /usr/local/lib/python2.5/site-packages/django/contrib/admin/media>
Order allow, deny
Options Indexes
Allow from all
IndexOptions FancyIndexing  
</ Directory>

WSGIScriptAlias ​​/ / mnt / www / mysite / apache / django.wsgi

<Directory /mnt/www/mysite>
Order deny, allow 
Allow from all
</ Directory>

<Directory /mnt/www/mysite/apache>
Allow from all
</ Directory>

create django.wsgi file, as follows:

import os, sys

# Calculate the path based on the location of the WSGI script.

apache_configuration = os.path.dirname (__file__)

project = os.path.dirname (apache_configuration)

workspace = os.path.dirname (project)

sys.path.append (workspace)

os.environ ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

os.environ ['PYTHON_EGG_CACHE'] = '/ tmp'

import django.core.handlers.wsgi

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

print>> sys.stderr, sys.path

I have followed these step but when I run it under Apache through a browser, I get a 500 Internet Server Error. Then I check the erro_log: it says:"TemplateSyntaxError: Caught ImportError while rendering: No module named friends" (friends is the name of one of my module)

The path of my site is /var/BigPrject/mysite

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

话少心凉 2024-11-13 01:36:50

对我来说一切看起来都很好,除了项目文件夹不在 python 路径中。

您可以通过转到控制台并尝试导入朋友来验证它。

我猜,在您的情况下,您可以通过将以下行添加到您的 wsgi 文件中来解决此问题:

sys.path.append (project)

Everything looks good to me, except the project folder is not in the python path.

You can validate it by going to the console and trying to import friends.

I am guessing, you can fix this, in you case, by adding the following line to your wsgi file:

sys.path.append (project)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文