El arquitecto
El arquitecto

Reputation: 533

Django pass empty parameter

I'm trying to pass an empty parameter to render a template but I can not achieve this I do not know if the problem is in urls.py or views, I really appreciate a hand.

Urls

url(r'^hola/(\b[a-z\.-]+)$', views.hola, name='hola'),

Views

def hola(request, varr = ''):
    #val = val
    pregunta = Datos_usuario_DB.objects.all().order_by('-id').filter(activo="1")[:15]
    plantilla = {'': 'index.html', 'nosotros': 'nosotros.html'}
    return render(request, plantilla['%s' % varr], {'pregunta': pregunta})

When I access to hola/ it says that the website does not exist.

Upvotes: 0

Views: 2044

Answers (2)

Dharmesh Fumakiya
Dharmesh Fumakiya

Reputation: 2338

your urls is not contains hola/ entry, so It returns error. If you want to call hola/, you need to add url in urls.py

Upvotes: 1

Alasdair
Alasdair

Reputation: 308849

If you want /hola/ to work, it's easy to add another URL pattern:

url(r'^hola/$', views.hola, name='hola'),
url(r'^hola/([a-z\.-]+)$', views.hola, name='hola'),

It's not clear to me why you have \b in the regex, so I removed it.

Upvotes: 3

Related Questions