【问题标题】:django1.3 static file problemdjango1.3 静态文件问题
【发布时间】:2011-11-21 06:41:15
【问题描述】:

嗨,我是 django 的新手,我正在为我的项目进行用户身份验证,它工作正常。
我在我的项目根文件夹中创建了一个名为“static”的文件夹[现在在本地开发中],并在 setting.py 中进行了必要的编辑,

我的第一个页面[包含登录表单]显示图像并成功使用 css 文件,如果登录成功帐户/配置文件 url 映射到视图,则依次 导致模板“LoginSuccess.html”,但不显示图像和 css 文件。

问题是它没有从静态文件夹中获取图像。 我的命令提示符如下所示

发现 0 个错误
Django 1.3 版,使用设置“SecondPrjt.settings”
开发服务器运行在 http://127.0.0.1:8000/
使用 CTRL-BREAK 退出服务器。
[2011 年 9 月 20 日 22:11:47]“GET / HTTP/1.1”200 5394
[2011 年 9 月 20 日 22:11:47]“GET /static/css/style.css HTTP/1.1”200 3612
[2011 年 9 月 20 日 22:11:47]“GET /static/images/favicon.ico HTTP/1.1”200 1150
[20/Sep/2011 22:12:10]“POST / HTTP/1.1”302 0

[20/Sep/2011 22:12:10]“GET /accounts/profile/HTTP/1.1”200 1930
[20/Sep/2011 22:12:10]“GET /accounts/profile/css/style.css HTTP/1.1”404 2758
[20/Sep/2011 22:12:10]“GET /accounts/profile/images/logo.jpg HTTP/1.1”404 2764
[2011 年 9 月 20 日 22:12:10]“GET /accounts/profile/images/rss.jpg HTTP/1.1”404 2761
[2011 年 9 月 20 日 22:12:10]“GET /accounts/profile/images/but1.gif HTTP/1.1”404 2764
也对与静态文件无关的 HTTP 302 感到困惑


注意: 我使用了一个 base.html(调用 css 文件,一些图像),它继承了我的所有模板
urls.py (r'^$',登录),
(r'^accounts/profile/$',views.loginsuccess),
(r'^accounts/logout/$',注销),

【问题讨论】:

    标签: django-templates django-forms django-views django-1.3


    【解决方案1】:

    渲染时忘记传递上下文的问题 return render_to_response('user/LoginSuccess.html',context_instance=RequestContext(request)

    【讨论】:

    • 谢谢,这对我帮助很大!
    猜你喜欢
    • 2012-01-17
    • 2011-06-11
    • 1970-01-01
    • 1970-01-01
    • 2013-11-22
    • 2020-11-06
    • 2021-08-23
    • 2018-10-21
    • 1970-01-01
    相关资源
    最近更新 更多