question about url

16 views
Skip to first unread message

luca72

unread,
Jan 9, 2014, 11:06:00 AM1/9/14
to django...@googlegroups.com
Hello
i have defined an url as:

(r'^tipi/(\w)', 'polls.views.tipi'),

the template is:

<div id="bordo_sx">
{% if variabile == "vino" %}
 <ul>
 {% for a in lista_vini %}
 <li><a href="/tipi/{{a}}">{{a}}</a></li>
 {% endfor %}
 </ul>
 {% endif %}
</div>

the view is:
def tipi(request,a):
  if a == 'Barbaresco':
    testo = ['Wine name: BARBARESCO','Region: Piedmont']
    titolo = 'Wines'
    variabile = 'vino'
    return render_to_response('vini.html',{'testo':testo,'titolo':titolo, 'testo':testo,'variabile':variabile,})

But i get that i don't have a http response where is the error?

Thanks Luca

Avraham Serour

unread,
Jan 9, 2014, 11:40:09 AM1/9/14
to django...@googlegroups.com
you are probably opening the wrong url, I also suggest using $ at the end of the regex


--
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...@googlegroups.com.
To post to this group, send email to django...@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/a1c96c85-0190-465d-a23f-8ad04d2b5792%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Tom Evans

unread,
Jan 9, 2014, 11:57:48 AM1/9/14
to django...@googlegroups.com
On Thu, Jan 9, 2014 at 11:06 AM, luca72 <luca...@libero.it> wrote:
> Hello
> i have defined an url as:
>
> (r'^tipi/(\w)', 'polls.views.tipi'),

The word 'tipi', followed by a forward slash, followed by a SINGLE
'word' character, and then any other characters before the end of the
URL (but none of them will be captured as an argument to your view,
only the first word character.)

>
> the template is:
>
> (not relevant)
>
> the view is:
> def tipi(request,a):
> if a == 'Barbaresco':
> testo = ['Wine name: BARBARESCO','Region: Piedmont']
> titolo = 'Wines'
> variabile = 'vino'
> return render_to_response('vini.html',{'testo':testo,'titolo':titolo,
> 'testo':testo,'variabile':variabile,})
>
> But i get that i don't have a http response where is the error?

The view only returns a http response if a == 'Barbaresco', if it is
any other value then your view returns nothing. A view must *always*
return a HttpResponse, in every circumstance.

Also, because of the URL issue I pointed out earlier, a will never
equal 'Barbarseco'; at most it will be 'B'.

Cheers

Tom
Reply all
Reply to author
Forward
0 new messages