簡體   English   中英

Django在評論后重定向

[英]Django redirect after comment post

我是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()),
)

在這里查看我的解決方案:Django: 評論發布后重定向到當前文章

它基本上使用由評論帖子url觸發的視圖,該視圖重定向回到原始引薦來源頁面。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM