亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

DoesNotExist at /profiles/user-profile/

DoesNotExist at /profiles/user-profile/

有只小跳蛙 2023-10-25 10:54:48
我正在嘗試添加跟隨切換,但在我看來,我在匹配查詢集時遇到錯誤。用戶配置文件存在于數據庫中,但我仍然不知道為什么會發生這種情況。我希望你能找出我的錯誤并告訴我如何解決它。我正在學習 Django,如果你能幫助我,那意義重大。我將感謝你。如果需要更多代碼來幫助我,我會分享。class UserProfileFollowToggle(View):    def post(self, request, *args, **kwargs):        print(request.POST)        user_to_toggle = request.POST.get('username')        print(user_to_toggle)        profile_ = UserProfile.objects.get(user__username__iexact=user_to_toggle)        user = request.user        if user in profile_.follower.all():            profile_.follower.remove(user)        else:            profile_.follower.add(user)        return redirect("/posts/list/") follow_toggle.html:<form class='form' method='POST' action={% url 'profiles:toggle' %}>{% csrf_token %}<input type='hidden' name='username' value="{% if username %}{{ username }} {% else %}{{ testuser }}{% endif %}"><button class='btn {% if is_following %}btn-default {% else %}btn-primary{% endif %}'>{% if is_following %}Unfollow {% else %}Follow{% endif %}</button></form>
查看完整描述

1 回答

?
阿波羅的戰車

TA貢獻1862條經驗 獲得超6個贊

它將在末尾呈現一個空格。因此,模板應如下所示:


#                                                                 no space ↓

<input type='hidden' name='username' value="{% if username %}{{ username }}{% else %}{{ testuser }}{% endif %}">



查看完整回答
反對 回復 2023-10-25
  • 1 回答
  • 0 關注
  • 179 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號