У меня есть обратная ошибка в Django при посещении другого URL "Comment_post_view" < /p>
Ошибка происходит от того, когда я посещаю страницу Comment_post_view; < /p>
Я думаю, может быть, из -за того, что имени пользователя в URL я не знаю, как с ним. Ниже приведены мои коды; Как это сделать?URL
path('p//status//', comment_post_view, name='comment_post_view'),
path('settings/archive-post/', archive_post_view, name='archive_post_view'),
path('archive-post//', archive_view, name='archive_view'),
VIEWS.PY
@login_required
def comment_post_view(request, username, post_id):
page_title = "Post Comment"
username_url = get_object_or_404(User, username=username)
user_post = get_object_or_404(Post, pk=post_id, poster_profile=username_url)
# All users following posts
user_profile = request.user.profile
posts = Post.objects.filter(
Q(id=user_post.id)
).order_by("?").select_related('poster_profile', 'poster_profile__profile').distinct()
post_data = []
for post in posts:
poster_profile = post.poster_profile.profile
mutual_followers_qs = user_profile.following.filter(
id__in=poster_profile.following.values_list('id', flat=True)
)
post_data.append({
'post': post,
'mutual_followers': mutual_followers_qs[:3], # You can select any number of followers here
'mutual_count': mutual_followers_qs[2:].count()
})
@login_required
def archive_post_view(request):
page_title = "Archive Post"
posts = Post.objects.filter(
Q(is_hide=request.user)
).select_related('poster_profile', 'poster_profile__profile').distinct()
post_data = []
for post in posts:
poster_profile = post.poster_profile.profile
post_data.append({
'post': post,
})
@login_required
def archive_view(request, id):
post = get_object_or_404(Post, id=id)
if post.is_hide.filter(id=request.user.id).exists():
post.is_hide.remove(request.user)
else:
post.is_hide.add(request.user)
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
TEMPLATE archive_post_view.html
{% for item in post_data %}
{% if request.user == item.post.poster_profile %}
Archive post # Current user
{% else %}
# Error pointing to this a href
Archive post # Other user
{% endif %}
{% endfor %}
Подробнее здесь: https://stackoverflow.com/questions/796 ... ror-django
Почему я получаю ошибку noreversematch - django [дублировать] ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Я получаю ошибку noreversematch при посещении другого URL - Django [дубликат]
Anonymous » » в форуме Python - 0 Ответы
- 12 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Я получаю сообщение об ошибке NoReverseMatch. Кто-нибудь знает, что я делаю неправильно?
Anonymous » » в форуме Python - 0 Ответы
- 14 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Я получаю сообщение об ошибке NoReverseMatch. Кто-нибудь знает, что я делаю неправильно?
Anonymous » » в форуме Python - 0 Ответы
- 17 Просмотры
-
Последнее сообщение Anonymous
-