Django的1.6服务使用别名与Apache静态管理文件 [英] django 1.6 serving static admin files using alias with apache

查看:159
本文介绍了Django的1.6服务使用别名与Apache静态管理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我转换Django的教程与Apache充分合作,而不是使用内置的的runserver命令。我得到了第一步的工作;让Apache来服务于静态文件(CSS)。现在,我需要得到它服务于静态文件的管理。

So I am converting the Django tutorial to fully work with Apache instead of using the built-in "runserver" command. I got step one working; getting Apache to serve the static files (css). Now I need to get it to serve the static files for the admin.

我的code迄今在为Apache 2.4 httpd.conf文件。

My code so far in the httpd.conf file for Apache 2.4.

#static files for site
Alias /static/ "C:/mysite/polls/static/"
<Directory "C:/mysite/polls/static">
Require all granted
</Directory>

#static files for admin
Alias /static/ "C:/Python27/Lib/site-packages/django/contrib/admin/static/"
<Directory "C:/Python27/Lib/site-packages/django/contrib/admin/static">
Require all granted
</Directory>

显然具有相同别名2号地块无法正常工作和CSS将不会加载为admin。该网站(1块)加载罚款。现在,这个页面中的Django教程详细介绍了如何使它工作的全过程。我只是不明白。也许我在这里和其他地方做一个语法错误,我已经阅读这个帖子不计其数

Obviously having the same alias for the 2nd block does not work and the CSS will not load for the admin. The site (1st block) loads fine. Now this page in the Django tutorial details the entire process on how to make it work. I just cannot figure it out. Maybe I am doing a syntax error and I have read countless posts about this both here and elsewhere.

doc文件提到了3种方式来做到这一点。我想这样做的第二个途径;通过使用别名指令的方式:使用Alias​​指令,如上文所示,别名合适的URL(可能STATIC_URL +管理员/)的管理文件的实际位置。

The doc mentions 3 ways to do it. I want to do it the 2nd way; by way of using the alias directive: "Use an Alias directive, as demonstrated above, to alias the appropriate URL (probably STATIC_URL + admin/) to the actual location of the admin files."

现在我不明白,它说:STATIC_URL +管理员/)确切的部分,我尝试了各种变化,但它不会工作,我的管理页面链接正是这一点:
http://127.0.0.1/admin/

Now I don't understand the exact part where it says "STATIC_URL + admin/). I tried various variations of that but it won't work. My link to the admin page is exactly this: http://127.0.0.1/admin/

我们能否在具体的数字了这一点,Windows和DJANGO 1.6?到Django的1.4有一个在settings.py文件中使用ADMIN_MEDIA_ preFIX以不同的方式之前,我知道了。这种方式去$ P $现在pcated,我想使用的别名。和奖金。如何别名正是工作的?

Can we figure this out in specific to WINDOWS and DJANGO 1.6? I know prior to DJANGO 1.4 there was a different way using "ADMIN_MEDIA_PREFIX" in the settings.py file. That way is deprecated now and I want to use the alias. And bonus. How do aliases exactly work?

谢谢大家。

编辑:
链接提及如何做到这一点。在服务管理文件我需要弄清楚使用别名第二种方法。
https://docs.djangoproject.com/en/1.6/howto/部署/ WSGI / modwsgi /

推荐答案

这是静态的应用程序是什么。你应该做 manage.py collectstatic 有关部署,而这会收集所有的静态内容 - 无论是为您的应用程序和内置/的contrib的 - 在一个地方,这在这里,您将您的Apache的别名。

This is what the "static" app is for. You should do manage.py collectstatic on deployment, and this collects all your static content - both for your apps and for the built-in/contrib ones - into one place, which is where you point your Apache alias to.

但如果你真的想硬code吧,STATIC_URL +管理只是手段正是:STATIC_URL的价值,以admin的后缀,所以别名/静态/管理员

But if you really want to hard code it, STATIC_URL + admin just means exactly that: the value of STATIC_URL, suffixed with "admin", so Alias /static/admin.

这篇关于Django的1.6服务使用别名与Apache静态管理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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