我是Django的新手,我试图理解,为什么我的代码而不是重定向到:
http://127.0.0.1:8000/object/2/
将我重定向到:
http://127.0.0.1:8000/object/2/?c=14
代码在哪里添加了这些参数?
模板:
{% if user.is_authenticated %}
{% get_comment_form for object as comment_form %}
<form action="{% comment_form_target %}" method="POST">
{% csrf_token %}
{{ comment_form.comment }}
{{ comment_form.content_type }}
{{ comment_form.object_pk }}
{{ comment_form.timestamp }}
{{ comment_form.security_hash }}
<input type="hidden" name="next" value="{{ object.get_absolute_url }}" />
<input type="submit" value="post comment" />
</form>
{% else %}
<p>Please <a href="{% url 'auth_login' %}">log in</a> to leave a comment.</p>
{% endif %}
views.py:
class realiz_photo_view(DetailView):
template_name = 'realization/realiz_photo.html'
model = realiz_photo
def get_context_data(self, **kwargs):
context = super(realiz_photo_view, self).get_context_data(**kwargs)
context["form"] = RealizationForm()
return context
urls.py:
url(r"^comments/", include("django.contrib.comments.urls")),
url(r'^object/', include('realization.urls')),
实现/ urls.py:
urlpatterns = patterns('',
url(r'^(?P<pk>\d+)/$', realiz_photo_view.as_view()),
)
答案 0 :(得分:0)
请在此处查看我的解决方案:Django:Redirect to current article after comment post
它基本上使用由评论发布网址触发的视图,该视图会重定向回原始引荐网页。