Friday, September 26, 2014

Re: 1 named url per page/screen?

On Thursday, 25 September 2014 22:43:43 UTC+1, Malik Rumi wrote:
1. I am trying to understand the documentation here: https://docs.djangoproject.com/en/1.7/topics/http/urls/#naming-url-patterns

Let us suppose I have a model and folder on mysite called Colors. Within Colors there are several individual documents: blue, green, yellow.

If blue, green, and yellow all use the same view and template, [and they're supposed to, aren't they?]  does this mean each url must be named 'blue' or 'green' or 'yellow' in order for Django to tell them apart?

That's how I'm reading this, but that doesn't make sense to me, because it seems to be about the same as hardcoding the url, and if you have a lot of pages it would be murder to have to do this for every page, and seems contrary to the whole notion of a dynamic web site.  So what am I missing here?


No, that's not what it means. It means you have one name per URL type: in your case, it would be for "colors", which can then take a parameter "blue" or "green" or whatever - exactly as the example you link to has "arch-summary" with a parameter of the year.
 

2. I am struggling with this error: 

" Reverse for 'colors_articleView' with arguments '()' and keyword arguments '{u'pk': '', u'slug': ''}' not found. 1 pattern(s) tried: ['colors/(?P<pk>\\d+)/(?P<slug>[\\w]+)'] "

I don't know what I'm missing here. I did a queryset for all the colors in a function based equivalent to list view and didn't see this error, but now that I want individual pages I can't resolve it. 

It shows that you are passing blank strings for the pk and slug parameters in the reverse call. Without seeing the code though we can't tell you why.
--
Daniel.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/34218427-f123-4de1-b0db-b9ff683ce6a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment