使用 Javascript 出现 302 和 404 错误
我正在尝试在我的 Django 站点中运行 WMDEditor。我已将 WMD 文件安装在网站根目录的 /static/js/wmd.wmd.js 目录中。
但是,当页面得到服务时,我得到:
INFO 2009-09-08 11:00:48,217 dev_appserver.py:3034] "GET /static/js/wmd/wmd.
js HTTP/1.1" 302 -
INFO 2009-09-08 11:00:48,733 dev_appserver.py:3034] "GET /static/js/wmd/wmd.
js/ HTTP/1.1" 404 -
I am trying to run WMDEditor in my Django site. I have installed WMD files in a directory called /static/js/wmd.wmd.js of the root of my website.
However when the page get served I get:
INFO 2009-09-08 11:00:48,217 dev_appserver.py:3034] "GET /static/js/wmd/wmd.
js HTTP/1.1" 302 -
INFO 2009-09-08 11:00:48,733 dev_appserver.py:3034] "GET /static/js/wmd/wmd.
js/ HTTP/1.1" 404 -
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我有一些类似的问题。确保您还添加到 app.yaml 文件中
I had some similar problems. Make sure you also add to your app.yaml file
发生的情况是重定向,因为 Django 认为您的 URL 应该以斜杠 (/) 结尾,但即使末尾有斜杠,该 url 显然也不正确。
将其添加到根 urls.py 文件中,并确保 settings.MEDIA_ROOT 是静态目录的绝对路径:
另请注意,在生产设置中,Django 不应提供静态文件。
What is happening is a redirect, because Django thinks your URLs should end with a slash (/), but even with a slash at the end, the url is obviously incorrect.
Add this to your root urls.py file and make sure that settings.MEDIA_ROOT is an absolute path to your static directory:
Also note that in a production setting static files should not be served by Django.
django 开发服务器自动提供管理静态文件。
但是,我不知道它对您自己添加的静态文件的行为如何。我已经让 WMDEditor 在生产环境中工作,但不在开发环境中工作。
本文概述了如何以一种黑客的方式在dev 环境来提供静态文件。但是,您需要在生产环境中设置别名。
The django dev server serves admin static files automagically.
However, I don't know how it behaves with static files you yourself add. I've gotten the WMDEditor working in a production enviroment, but not a dev one.
This article outlines how to get a hackish way to work in the dev enviroment to serve static files. You'll want to set up an alias in the production enviroment however.