Django pass parameter does not work

-1

I hope you can help me, I'm trying to make a function in which passing the parameter can render different template but I do not know what is wrong if the views or the url, someone helps me?

views.

def hola(request, par):
    #val = val
    pregunta = Datos_usuario_DB.objects.all().order_by('-id').filter(activo="1")[:15]
    respuesta = Datos_respuesta_DB.objects.all().order_by('-id')[:15]
    preguntarespuesta = zip(pregunta, respuesta)
    #pregunta2 = [{'nombre':'hh'},{'nombre':'hhsss'}]
    plantilla = {'': 'index.html', 'nosotros': 'nosotros.html', 'contacto': 'contacto.html'}
    return render(request, plantilla['%s' % par], {'preguntarespuesta': preguntarespuesta})
    #return HttpResponse(val)

urls

url(r'^[a-z\.-]+$', views.hola, name='hola'),
    
asked by El arquitecto 27.09.2017 в 17:59
source

1 answer

0

Your url is poorly defined. You did not define the name of your parameter in the url. Maybe you can check the tutorial . But beyond that, I think what you want is something like this:

url(r'^(?P<par>[a-z\.-]+)/$', views.hola, name='hola'),
    
answered by 01.10.2017 в 03:11