我的页面之一,静态 url 未正确呈现。例如:
<link href="//static/static/css/style.css" rel="stylesheet">
这是一个联系表格,下面是视图:
def contact(request):
Success = False
email = ""
title = ""
text = ""
if request.method == "POST":
contact_form = ContactForm(request.POST)
if contact_form.is_valid():
Success = True
email = contact_form.cleaned_data['email']
title = contact_form.cleaned_data['title']
text = contact_form.cleaned_data['text']
else:
contact_form = ContactForm()
ctx = {'contact_form':contact_form, 'email':email, 'title':title, 'text':text, 'success':success}
return render_to_response('website/contact.html', ctx, context_instance=RequestContext(request))
模板:
{% if success %}
<p>{{ email }}</p>
<p>{{ title }}</p>
<p>{{ text }}</p>
{% else %}
<form action"." method="POST">
{{ contact_form.as_p }}
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
{% endif %}
所有其他页面都在正确加载,唯一的区别是这种形式。有谁知道发生了什么?
编辑:
呈现 url 的模板代码是:
<link href="/{{ STATIC_URL }}static/css/bootstrap.css" rel="stylesheet">
以及相关的settings.py代码:
STATIC_ROOT = os.path.join(os.path.dirname(__file__), "static")
CURRENT_PATH = os.path.abspath(os.path.dirname(__file__).decode('utf-8')).replace('\\', '/')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(CURRENT_PATH, '/static/'),
)