Re: NoReverseMatch in Django (url ploblem)

2015-07-05 Thread Jeff Gaoey
James - Thank You Very Much

that true it doesn't need /. everything work fine as I want :D.

เมื่อ วันศุกร์ที่ 3 กรกฎาคม ค.ศ. 2015 7 นาฬิกา 38 นาที 54 วินาที UTC+7, 
James Schneider เขียนว่า:
>
>
> > > I'm a beginner of Django I want to set my url with database field_name
> > > instead of use primary key from Django tutorial. This is my code.
> > >
> > > *mysite*
> > > **dwru/urls.py**
> > > urlpatterns = [
> > > url(r'^$', include('product.urls', namespace="product")),
> > > ]
> >
> > This regex is incorrect, and will only match a URL of '/', which is
> > probably not what you want (since you are making other URL's like
> > '/TestCA01' down below). You need to remove the $ from the regex to
> > pass along the entire URL string to the include. You probably need a
> > slash in there also to remove it as a prefix when it is passed along
> > to the include:
> >
> > url(r'^/', include('product.urls', namespace="product")),
> >
>
> I was thinking about this and you may not need the /, if it doesn't work, 
> try without it. I'm not in front of a computer to verify.
>
> -James
>  

-- 
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+unsubscr...@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/e779ffbb-2480-4dc6-998f-dc7bfec97b2e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: NoReverseMatch in Django (url ploblem)

2015-07-02 Thread James Schneider
> > I'm a beginner of Django I want to set my url with database field_name
> > instead of use primary key from Django tutorial. This is my code.
> >
> > *mysite*
> > **dwru/urls.py**
> > urlpatterns = [
> > url(r'^$', include('product.urls', namespace="product")),
> > ]
>
> This regex is incorrect, and will only match a URL of '/', which is
> probably not what you want (since you are making other URL's like
> '/TestCA01' down below). You need to remove the $ from the regex to
> pass along the entire URL string to the include. You probably need a
> slash in there also to remove it as a prefix when it is passed along
> to the include:
>
> url(r'^/', include('product.urls', namespace="product")),
>

I was thinking about this and you may not need the /, if it doesn't work,
try without it. I'm not in front of a computer to verify.

-James

-- 
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+unsubscr...@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/CA%2Be%2BciUD%2BvTpS71q2EGz8F-Qc9StWtOxx%3Df2WTHWmdtKzQX6Fw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: NoReverseMatch in Django (url ploblem)

2015-07-02 Thread James Schneider
> I'm a beginner of Django I want to set my url with database field_name
> instead of use primary key from Django tutorial. This is my code.
>
> *mysite*
> **dwru/urls.py**
> urlpatterns = [
> url(r'^$', include('product.urls', namespace="product")),
> ]

This regex is incorrect, and will only match a URL of '/', which is
probably not what you want (since you are making other URL's like
'/TestCA01' down below). You need to remove the $ from the regex to
pass along the entire URL string to the include. You probably need a
slash in there also to remove it as a prefix when it is passed along
to the include:

url(r'^/', include('product.urls', namespace="product")),


>
> *myapp*
> **product/urls.py**
> urlpatterns = [
>url(r'^$', views.index, name='index'),
>url(r'^(?P[-_\w]+)/$', views.product_list_from_index,
> name='catalog'),
> ]


Assuming you fix the issue above, after a cursory glance this looks
fine. Just a note that \w includes the underscore, so you can remove
that as one of the potential matching characters.


>
> **product/views.py**
> def product_list_from_index(request, name_catalog):
>catalog = get_object_or_404(Catalog, name_catalog=name_catalog)
>context = {
>'catalog': catalog
> }
>return render(request,'product/product_list.html', context)
>
>
> **product/models.py**
> class Catalog(models.Model):
>   name_catalog = models.CharField(max_length=45)
>   product = models.ManyToManyField(Product)
>
> **template/product/index.html**
> {% for catalog in catalog_list %}
> {{
> catalog.name_catalog }}
> {% endfor %}
>
> Then I add Catalog field with "TestCa01" then it shown an error
>
> NoReverseMatch at /
> Reverse for 'catalog' with arguments '(u'TestCa01',)' and keyword arguments
> '{}' not found. 1 pattern(s) tried: [u'$(?P[-_\\w]+)/$']
>

It's odd that the regex is showing prefixed with a $ (I can't recall
seeing that before), that would indicate that it is looking for the
end of the line at the beginning of the regex statement, which means
the rest of the statement will never match. This may be an artifact
from the regex issue above.


> it kind of some problem with this line in template
>
> {% url 'product:catalog' catalog.name_catalog %}
>
> any Idea?
>

Unfortunately, it's hard to pinpoint in the error message what exactly
broke. Someone submitted a ticket a while back to make the error
message more concise and point people back to their URL confs. It was
closed because the list of URL regex's is now displayed.

https://code.djangoproject.com/ticket/14343


While I'm not deeply familiar with the code behind the URL resolver
functions, fixing the initial regex will need to be done regardless.
My wild guess would be that it properly fills in the value for
P, but sine the include statement is incorrect (and will
ignore anything after the initial / in the requested URL), the string
doesn't match  when the regex is checked.

-James

-- 
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+unsubscr...@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/CA%2Be%2BciVVL53juBEM1fz_uJrQkaY76iiyy02nxv1CRxUkiDodAg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


NoReverseMatch in Django (url ploblem)

2015-07-02 Thread Jeff Gaoey


I'm a beginner of Django I want to set my url with database field_name 
instead of use primary key from Django tutorial. This is my code.

*mysite***dwru/urls.py**
urlpatterns = [
url(r'^$', include('product.urls', namespace="product")),]
*myapp***product/urls.py**
urlpatterns = [
   url(r'^$', views.index, name='index'),
   url(r'^(?P[-_\w]+)/$', views.product_list_from_index, 
name='catalog'),]
**product/views.py**def product_list_from_index(request, name_catalog):
   catalog = get_object_or_404(Catalog, name_catalog=name_catalog)
   context = {
   'catalog': catalog}
   return render(request,'product/product_list.html', context)

**product/models.py**class Catalog(models.Model):
  name_catalog = models.CharField(max_length=45)
  product = models.ManyToManyField(Product)
**template/product/index.html**{% for catalog in catalog_list %}
{{ 
catalog.name_catalog }}{% endfor %}

Then I add Catalog field with "TestCa01" then it shown an error

NoReverseMatch at /Reverse for 'catalog' with arguments '(u'TestCa01',)' and 
keyword arguments '{}' not found. 1 pattern(s) tried: 
[u'$(?P[-_\\w]+)/$']

it kind of some problem with this line in template

{% url 'product:catalog' catalog.name_catalog %}

any Idea?

-- 
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+unsubscr...@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/65b8fb8e-02ae-4441-88cc-114eb662cdee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.