Why do I keep getting this error all the time? NoReverseMatch at /

how so? I imported it from the .models py

look at this code, it s given profle as argument, hellooo

page_user = get_object_or_404(**Profile**, id=self.kwargs['pk'])

Ok, you need to take a step back and start here: Writing your first Django app, part 1 | Django documentation | Django

You’re clearly not understanding how models work.

im done here, its not for me, thank you

what is wrong with this model:

class Profile(models.Model):
	user = models.OneToOneField(User, null=True, on_delete=models.CASCADE)
	bio = models.TextField()
	profile_pic = models.ImageField(null=True,blank=True,upload_to='images/profile')



	def _str_from_(self):
		return self.user

omg what is wrong this model? jeeesusssss

There’s nothing wrong with the model. The model itself isn’t the issue.

There is however, a significant difference between a model and the instances of that model - and that’s what you need to reinforce your understanding of, by working your way through the tutorial.

ohh so now youre telling me the fields in the model are wrong?

Nope, I’m not saying that at all. In fact, I said just the opposite:

There is however, a significant difference between a model and the instances of that model

what does that mean??

And that brings us back around to this:

I’m not going to retype everything from the tutorial that you need to understand at this point. It’s all there.

i already followed this tutorial, i keep telling.
I still get the error.
what new will i learn there?
there is nothing new to learn.
Why do you keep sending me there?
If you don’t know of a solution dont reply to me threads.

Did you actually work your way through the tutorial? (Not just copy/paste the code for the examples, but physically type them in?)

Either way, if you work your way thought the first 4 pages again, you will learn more than you did the first time around.

You will learn the difference between a model and the instances of data in the model.

Because you’re displaying a lack of fundamental understanding of how Django and Python work. That would be a lot of ground to cover for the volunteers here who try to answer questions, when the answers to those questions are already explained in detail elsewhere.

Actually, the specific solution was identified here: Why do I keep getting this error all the time? NoReverseMatch at / - #41 by KenWhitesell

That you don’t understand that it is the answer to your issue is the sign that you need to work your way through the tutorial again, with the mindset of understanding what you are doing each step of the way.

You need to chill and understand that:

  1. It is more than just ā€œfollowingā€ the toturial
  2. It is about understanding each line/piece of code from the tutorial

If you fail to thouroughly follow those steps, you are not going to get very far at all.

before I start re-reading the docs again and follow the tutorial there, can you please explain why this code works flawlessly, and the other not? Just this one last question:


class Product(models.Model):
	title = models.CharField(max_length=2550,null=True)
	title_headline = models.CharField(max_length=25500,null=True)
	short_description = models.TextField(max_length=25000,null=True)
	description = models.TextField(max_length=50000,null=True)
	featured_image = models.ImageField(max_length=300,null=True,upload_to='media')

	def __str__(self):
		return self.title or ' '
class ProductDetailsView(generic.DetailView):

	model = Product
	template_name = 'product_details.html'

	def get_context_data(self,*args,**kwargs):

		product = get_object_or_404(Product,id=self.kwargs['pk'])
		context = super(ProductDetailsView,self).get_context_data(*args,**kwargs)
		context['product']=product

		return context

<a href="{% url 'products_details_url' pk=product.pk %}">{{product.title}}</a>

thank you

I followed the tutorial word by word and get this error again when I rich the id and pk stuff. I dont know why its not working?
what does this mean now?

def detail(request, question_id):
	return HttpResponse("You are looking at question %s. " % question_id)

def results(request, question_id):
	return HttpResponse(response % question_id)

def vote(request, question_id):
	return HttpResponse("You are voting on question %s. " % question_id)
urlpatterns = [
    path('', views.index, name='index'),

    path('<int:question_id>/', views.detail, name='detail'),
    path('<int:question_id>/results/', views.results, name='results'),
    path('<int:question_id>/vote/', views.vote, name='vote'),
]

Page not found (404)
Request Method:	GET
Request URL:	http://127.0.0.1:8000/polls_app/1
Using the URLconf defined in polls.urls, Django tried these URL patterns, in this order:

admin/
[name='index']
<int:question_id>/ [name='detail']
<int:question_id>/results/ [name='results']
<int:question_id>/vote/ [name='vote']
The current path, polls_app/1, didn’t match any of these.

Again this is the tutorial on Django Documentation, what can go wrong here?

Does Django hate me or something? lol

Where is ā€œpolls_appā€ coming from here? I’m not aware of any url in the tutorial using that identifier.

Your file containing this:

What file is this in and in which directory?

HAHA. i AM HAVING THE SAME THING

1 Like

This just helped me solve an issue i have been battling for an hour now. Thank you.

1 Like