[英]Django. Reply for comments getting posted as comments. How to have the reply for comments?
[英]Django Comments app: How do I disable the redirection to posted.html?
我正在使用Django的注釋框架 。 每當有人發表評論時,他都會被重定向到成功頁面( posted.html
)。 我不希望顯示成功頁面。 我只希望重新加載當前頁面(帶有新注釋)。 如何停止重定向?
添加一個名為next
的隱藏表單字段是可行的方法,但是您應該使用request.get_full_path
因為request.path
不包含查詢字符串:
<input type="hidden" name="next" value="{{ request.get_full_path }}" />
通過瀏覽contrib.comments.views.comments中的源代碼,您似乎可以提供“ next”參數來覆蓋重定向的位置。
#django.contrib.comments.views.comments
@csrf_protect
@require_POST
def post_comment(request, next=None, using=None):
#more code here...
# Check to see if the POST data overrides the view's next argument.
next = data.get("next", next)
#more code here...
我會嘗試在注釋表單中添加一個隱藏字段,其名稱為“ next”和您正在使用的當前url的值。 如果這不起作用,則可能必須提供您自己的視圖和URL。 希望有效!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.