我的URL路径有问题。
每当我删除-path('<query>/follow', views.follow, name='follow')
时-一切正常。当我添加它时,带有链接的页面将显示'Reverse for 'follow' with no arguments not found'
,尽管我可以手动在URL中键入跟随路径,但它成功。为什么会这样,我该如何解决?
html
<a href="{% url 'follow' %}">Follow</a>
urls.py
urlpatterns = [
path('', views.explore, name='explore'),
path('happening/profile/', views.profile, name='profile'),
path('happening/', views.happening, name='happening'),
path('home/', views.home, name='home'),
path('home/likes/', views.likes, name='likes'),
path('<query>/follow', views.follow, name='follow'),
path('<query>/', views.profpage, name='profpage'),
]
views.py
def profpage(request, query):
obj = User.objects.filter(username=query)
if not obj:
attempt = {'user':query}
return render(request, 'error.html', attempt)
try:
obj2 = reversed(get_list_or_404(Comments, user=query))
except:
obj2= {}
try:
obj3 = get_list_or_404(Comments, user=query)
except:
obj3 = {}
like_dict={}
for x in obj3:
likes = x.likes.all().count()
like_dict[int(x.id)] = int(likes)
img = UserProfile.objects.filter(user__username=query)
for x in obj:
obj = x
for x in img:
img=x
content = {'obj': obj,
'img':img,
'info':obj2,
'like_dict':like_dict,
'query':query,
}
return render(request, 'profpage.html', content)
def follow(request, query):
print("WORKING")
return HttpResponse(request)