apache2/mod_wsgi 上的 Django 和collectstatic

发布于 2025-01-03 16:49:39 字数 2194 浏览 1 评论 0原文

我正在 Ubuntu 11.04 下的 Apache 上配置 Django。我的媒体文件不可用。

httpd.conf

Alias /robots.txt /home/i159/workspace/prod-shivablog/shivablog/robots.txt
Alias /favicon.ico /home/i159/workspace/prod-shivablog/shivalog/favicon.ico

AliasMatch ^/([^/]*\.css) /home/i159/workspace/prod-     shivablog/shivablog/site_media/static/css/$1

Alias /media/ /home/i159/workspace/prod-shivablog/shivablog/site_media/static/
Alias /static/ /home/i159/workspace/prod-shivablog/shivablog/site_media/static/

<Directory /home/i159/workspace/prod-shivablog/shivablog/static>
Order deny,allow
Allow from all
</Directory>

<Directory /home/i159/workspace/prod-shivablog/shivablog/media>
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias / /home/i159/workspace/prod-shivablog/shivablog/deploy/wsgi.py
WSGIDaemonProcess local-shivablog.com python-path=/home/i159/workspace/prod-    shivablog/shivablog/:/home/i159/.envs/shivablog/python2.7/site-packages

<Directory /home/i159/workspace/prod-shivablog/shivablog>
<Files wsgi.py>
Order allow,deny
Allow from all
</Files>
</Directory>

urls

# Static files url.
(r'^media/(?P<path>.*)$', 'django.views.static.serve',
                                   {'document_root': settings.MEDIA_ROOT}),
(r'^site_media/static/(?P<path>.*)$', 'django.views.static.serve',
                                {'document_root': settings.STATIC_ROOT}),

wsgi

import os, sys

sys.path.insert(0,  os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir,  os.pardir)))
sys.path.insert(0,  os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir)))

from django.core.handlers.wsgi import WSGIHandler
os.environ["DJANGO_SETTINGS_MODULE"] = "shivablog.settings"
application = WSGIHandler()

设置

MEDIA_ROOT = ''

MEDIA_URL = "/media/"

STATIC_ROOT = ''

STATIC_URL = "/site_media/static/"

如何使我的媒体文件可用?哪些配置是正确的? collectstatic 之后,所有静态和媒体文件都会收集到 site_media/static。我应该从该目录 (site_media/static) 获取媒体文件吗?

I'm configuring Django on Apache under Ubuntu 11.04. My media files is not available.

httpd.conf

Alias /robots.txt /home/i159/workspace/prod-shivablog/shivablog/robots.txt
Alias /favicon.ico /home/i159/workspace/prod-shivablog/shivalog/favicon.ico

AliasMatch ^/([^/]*\.css) /home/i159/workspace/prod-     shivablog/shivablog/site_media/static/css/$1

Alias /media/ /home/i159/workspace/prod-shivablog/shivablog/site_media/static/
Alias /static/ /home/i159/workspace/prod-shivablog/shivablog/site_media/static/

<Directory /home/i159/workspace/prod-shivablog/shivablog/static>
Order deny,allow
Allow from all
</Directory>

<Directory /home/i159/workspace/prod-shivablog/shivablog/media>
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias / /home/i159/workspace/prod-shivablog/shivablog/deploy/wsgi.py
WSGIDaemonProcess local-shivablog.com python-path=/home/i159/workspace/prod-    shivablog/shivablog/:/home/i159/.envs/shivablog/python2.7/site-packages

<Directory /home/i159/workspace/prod-shivablog/shivablog>
<Files wsgi.py>
Order allow,deny
Allow from all
</Files>
</Directory>

urls

# Static files url.
(r'^media/(?P<path>.*)

wsgi

import os, sys

sys.path.insert(0,  os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir,  os.pardir)))
sys.path.insert(0,  os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir)))

from django.core.handlers.wsgi import WSGIHandler
os.environ["DJANGO_SETTINGS_MODULE"] = "shivablog.settings"
application = WSGIHandler()

settings

MEDIA_ROOT = ''

MEDIA_URL = "/media/"

STATIC_ROOT = ''

STATIC_URL = "/site_media/static/"

How to make my media files available? What the configurations are correct? After collectstatic all the static and media files collects to site_media/static. Should I get my media files from this directory (site_media/static)?

, 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), (r'^site_media/static/(?P<path>.*)

wsgi


settings


How to make my media files available? What the configurations are correct? After collectstatic all the static and media files collects to site_media/static. Should I get my media files from this directory (site_media/static)?

, 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),

wsgi

settings

How to make my media files available? What the configurations are correct? After collectstatic all the static and media files collects to site_media/static. Should I get my media files from this directory (site_media/static)?

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

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

发布评论

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

评论(1

缺⑴份安定 2025-01-10 16:49:39

您的 urls.py 文件中不应包含媒体或静态文件的条目。如果您至少将它们包装在一个仅在调试模式下执行此操作的原因中= True。

https://docs.djangoproject.com/en/1.2/howto/static- files/

(r'^media/(?P<path>.*)

另外,您的 .htaccess 文件具有以下几行指向同一文件夹,我认为它们应该不同,因为您的静态文件不在媒体文件夹中。

Alias /media/ /home/i159/workspace/prod-shivablog/shivablog/site_media/static/
Alias /static/ /home/i159/workspace/prod-shivablog/shivablog/site_media/static/
, 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), (r'^site_media/static/(?P<path>.*)

另外,您的 .htaccess 文件具有以下几行指向同一文件夹,我认为它们应该不同,因为您的静态文件不在媒体文件夹中。


, 'django.views.static.serve',
                                {'document_root': settings.STATIC_ROOT}),

另外,您的 .htaccess 文件具有以下几行指向同一文件夹,我认为它们应该不同,因为您的静态文件不在媒体文件夹中。

You should not have an entry in your urls.py file for media or static files. If you do at least wrap them in a cause which only does this in debug mode = True.

https://docs.djangoproject.com/en/1.2/howto/static-files/

(r'^media/(?P<path>.*)

Also your .htaccess file has the following lines which point to the same folder, I think they should be different as your static files are not in your media folder.

Alias /media/ /home/i159/workspace/prod-shivablog/shivablog/site_media/static/
Alias /static/ /home/i159/workspace/prod-shivablog/shivablog/site_media/static/
, 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), (r'^site_media/static/(?P<path>.*)

Also your .htaccess file has the following lines which point to the same folder, I think they should be different as your static files are not in your media folder.


, 'django.views.static.serve',
                                {'document_root': settings.STATIC_ROOT}),

Also your .htaccess file has the following lines which point to the same folder, I think they should be different as your static files are not in your media folder.

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