简体   繁体   English

Django在评论后重定向

[英]Django redirect after comment post

Im new to Django, and im trying to understand, why my code instead of redirect to : 我是Django的新手,我想了解为什么我的代码而不是重定向到:

http://127.0.0.1:8000/object/2/

redirect me to: 重定向到:

http://127.0.0.1:8000/object/2/?c=14

Where is the code, that adds this parameters? 添加此参数的代码在哪里?

Template: 模板:

{% 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: 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: urls.py:

url(r"^comments/", include("django.contrib.comments.urls")),
url(r'^object/', include('realization.urls')),

realization/urls.py: 实现/urls.py:

urlpatterns = patterns('',
url(r'^(?P<pk>\d+)/$', realiz_photo_view.as_view()),
)

See my solution here: Django: Redirect to current article after comment post 在这里查看我的解决方案:Django: 评论发布后重定向到当前文章

It basically uses a view that's triggered by the comment post url which redirects back to the original referrer page. 它基本上使用由评论帖子url触发的视图,该视图重定向回到原始引荐来源页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM