Reputation: 204
I have some problem in django 1.7.7. I can not use {{ request.path }} in template with django 1.7.7, but in django 1.6, I can do that.
Config template in setting.py to use {{ request }} in django 1.7.7:
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [
os.path.join(PACKAGE_ROOT, "templates"),
],
"APP_DIRS": True,
"OPTIONS": {
"debug": DEBUG,
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.core.context_processors.request",
"django.contrib.messages.context_processors.messages",
"pinax_theme_bootstrap.context_processors.theme",
],
},
},]
and in django 1.6:
TEMPLATE_CONTEXT_PROCESSORS = [
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.core.context_processors.request",
"django.contrib.messages.context_processors.messages",
"pinax_theme_bootstrap.context_processors.theme",
"allauth.account.context_processors.account",
"django.core.context_processors.request"]
And my template html
{% extends "base.html" %}
{% load i18n %}
{% load url from future %}
{% block body_class %}home{% endblock %}
{% block body_base %}
{{ request.path }}
<div class="row">
<form class="answer-question-form" method="POST" action="/add_answer_question">
{% csrf_token %}
<div class="col-md-12" style="padding-left: 0px; padding-right: 0px">
<div class="form-group col-md-12">
<label>Question</label>
<input type="text" class="form-control" name="question" placeholder="Question...">
</div>
<div class="form-group col-md-6 col-sm-12">
<label>Choose type question</label>
<select class="form-control" name="categories">
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
</select>
</div>
<div class="form-group col-md-12">
<label>Type answer</label>
<ul class="nav nav-pills nav-justified choose-type-answer">
<li class="active"><a class="type-answer" href="#" id="type-answer-01">Radio</a></li>
<li><a class="type-answer" href="#" id="type-answer-02">Check</a></li>
<li><a class="type-answer" href="#" id="type-answer-03">Seek</a></li>
</ul>
<input name="type-answers" type="hidden" value="01">
</div>
<div class="form-group answers col-md-12">
<label>Answers</label>
<input name="answer" type="text" class="form-control answer-detail" placeholder="Input answer here...">
<input name="answer" type="text" class="form-control answer-detail" placeholder="Input answer here...">
</div>
<div class="form-group col-md-12">
<button class="btn btn-default pull-right" id="submit">Submit</button>
</div>
</div>
</form>
</div>
{% endblock %}
So, I added "django.core.context_processors.request" to template but it doesn't work.
Plese help me! Thanks
Upvotes: 1
Views: 1321
Reputation: 2569
Remove the :
"OPTIONS": {
"debug": DEBUG,
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.core.context_processors.request",
"django.contrib.messages.context_processors.messages",
"pinax_theme_bootstrap.context_processors.theme",
],
},
Add :
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages"
"django.core.context_processors.request",
)
Nowhere in the documentation 1.7, they mention the "OPTIONS", only in the doc 1.8,
If you aren't rendering the request, like docs says:
If you’re using Django’s render_to_response() shortcut to populate a template with the contents of a dictionary, your template will be passed a Context instance by default (not a RequestContext). To use a RequestContext in your template rendering, use the render() shortcut which is the same as a call to render_to_response() with a context_instance argument that forces the use of a RequestContext.
Maybe the problem is on yours views. try to use render instead of render_to_response (if you use it)
Upvotes: 2