Answer the question
In order to leave comments, you need to log in
django NoReverseMatch error?
I decided to master django, I thought that it would be enough to repeat everything after the man from the video, I need to try something myself without prompts and I ran into this.
Reverse for 'boss' with no arguments not found. 1 pattern(s) tried: ['mymeteo/gorod/(?P[0-9]+)/$']
Request Method: GET
Request URL: 127.0.0.1:8000/mymeteo/gorod/4
Django Version: 3.0. 3
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'boss' with no arguments not found. 1 pattern(s) tried: ['mymeteo/gorod/(?P[0-9]+)/$']
Exception Location: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site -packages/django/urls/resolvers.py in _reverse_with_prefix, line 677
Python Executable: /Library/Frameworks/Python.framework/Versions/3.
Python Version: 3.8.1
Python Path:
['/Users/stepan/Desktop/django-pyowm/meteo',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zip',
'/Library/ Frameworks/Python.framework/Versions/3.8/lib/python3.8',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload',
'/Library/Frameworks/Python. framework/Versions/3.8/lib/python3.8/site-packages'] Server time: Tue, 10 Mar
2020
07:30:43
+0000
.py
from django.urls import path, include
from . import views
urlpatterns = [
path ('list/', views.ListGorod.as_view(), name = 'listgorod'),
path ('gorod/<int:id>/', views.MeteoList.as_view(), name = 'boss'),
]
class MeteoList(View):
def get (self, request, id):
obj = Gorod.objects.get ( id__iexact = id)
form = GorodForm(instance=obj)
try:
o=pyowm.OWM("262fea7ee569218476043b47466017ea")
obs=o.weather_at_place(obj.gorod)
w=obs.get_weather()
except:
o=pyowm.OWM("262fea7ee569218476043b47466017ea")
obs=o.weather_at_place('biysk, RUS')
w=obs.get_weather()
wind = w.get_wind()
temperature = w.get_temperature('celsius')
return render(request, 'mymeteo/meteo_list.html', context ={'temp' : w, 'temperature' : temperature, 'form':form})
def post (self, request, id):
obj = Gorod.objects.get (id__iexact = id)
b_form = GorodForm(request.POST, instance=obj)
new_obg = b_form.save()
try:
o=pyowm.OWM("262fea7ee569218476043b47466017ea")
obs=o.weather_at_place(obj.gorod)
w=obs.get_weather()
except:
o=pyowm.OWM("262fea7ee569218476043b47466017ea")
obs=o.weather_at_place('biysk, RUS')
w=obs.get_weather()
wind = w.get_wind()
temperature = w.get_temperature('celsius')
return render(request, 'mymeteo/meteo_list.html', context ={'temp' : w, 'temperature' : temperature, 'form':form})
return redirect(new_obg)
class Gorod (models.Model):
gorod = models.CharField(max_length = 50)
def get_absolute_url(self):
return reverse("boss", kwargs={"id" : self.id})
def __str__ (self):
return self.gorod
Answer the question
In order to leave comments, you need to log in
problem solved. it turned out to be very stupid of course .. but if it suddenly comes in handy ...
then in the template of this page in the form tag in actions there was the wrong address
thanks to everyone who tried to help)
ps in the end everything works and in get_absolute_url I still have kwargs
the text of the error shows what janga will turn your urls into. And there is not a single kwarg in that url, so you need to write reverse("boss", args=[self.id])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question