Я пытаюсь получить содержимое поля командой queryset 'Post.objects.values (' country__name ')' и получаю следующую ошибку.
NoReverseMatch at /
Reverse for 'cities' with arguments '('',)' not found. 1 pattern(s) tried: ['accounts\\/cabinet\\/cities\\/(?P<pk>[0-9]+)\\/$']
Хотя я не получаю никакой ошибки при вводе этой команды в оболочке django.
мой взгляд:
def home(request):
user = User.objects.all()
cname = request.POST.get('dropdown1')
city = Post.objects.all().distinct('city')
country = Post.objects.values('country__name')
print(country)
context = {
'country': country,
'user': user,
'city': city
}
return render(request, 'registration/home.html', context)
моя модель:
class Post(models.Model):
title = models.CharField(max_length=255)
country = models.ForeignKey(Country, on_delete=models.CASCADE)
city = models.CharField(max_length=255)
address = models.CharField(max_length=255)
email = models.EmailField(max_length=255)
phone = models.CharField(max_length=255)
website = models.URLField(max_length=255, blank=True)
date_posted = models.DateTimeField(default=timezone.now)
author = models.ForeignKey(User, on_delete=models.CASCADE)
def __str__(self):
return self.city
def get_absolute_url(self):
return reverse('users:blog')
my urls.py
urlpatterns = [
path('accounts/register/', UserRegistrationView.as_view(), name='register'),
path('accounts/cabinet/', views.profile, name='cabinet'),
path('accounts/cabinet/blog/<int:pk>/', PostDetailView.as_view(), name='post-detail'),
path('accounts/cabinet/new/', PostCreateView.as_view(), name='post-create'),
path('accounts/cabinet/blog/<int:pk>/update/', PostUpdateView.as_view(), name='post-update'),
path('accounts/cabinet/blog/<int:pk>/delete/', PostDeleteView.as_view(), name='post-delete'),
path('', views.home, name='home'),
path('accounts/cabinet/blog/', views.blog, name='blog'),
path('accounts/cabinet/countries/', views.countries, name='countries'),
path('accounts/cabinet/cities/<int:pk>/', views.cities, name='cities'),
path('accounts/cabinet/address/<int:pk>/', views.address, name='address'),
]