0

I'm working through various Django tutorials in order to get an LDAP Backend up and running. I have a simple login page using a user's credentials, and an extra field to insert a user to be searched for. When hitting the submit button on my page, I get redirected to the correct html, but the url remains the same. I'm not sure that this could pose any problems, but if not, does it really matter if a different page has the same url? How should I be calling the redirected page?

urls.py

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', ldap_authentication, name='index'),
    url(r'^logout/$', logout_view, name='logout'),
    url(r'^search_page/$', ldap_authentication, name="search_page")
] 

views.py

def ldap_authentication(request):             
    if request.POST:
        username = request.POST['username']
        password = request.POST['password']
        searchFilter = request.POST['searchUser']
        domain_and_login = '{}\\{}'.format(DOMAIN_NAME, username)

    '''
    Connection to LDAP...
    '''
    split_dn = [domain_and_login, "ou=Konzern", "dc=abcdef", "dc=de"]
    return render(request, 'search_page.html', {'dn':split_dn})

return render(request, 'login.html')

If I do a redirect, then I understand that Django looks this up in the urls.py, however the search_page.html doesn't have any view in the views.py.

pymat
  • 1,090
  • 1
  • 23
  • 45
  • If you want to redirect to the url named "search_page", you need to use [reverse()](https://docs.djangoproject.com/en/1.11/ref/urlresolvers/#reverse), I don't see that in your code? Also, if you want to redirect to return a HTTPResponseRedirect, now you're just returning a normal HTTPresponse. – DA-- Jul 02 '17 at 11:19
  • @DA but does this not mean, that I must have a view in my views.py? At the moment I currently don't need a view. – pymat Jul 02 '17 at 11:23
  • I think it really depends on how you want to achieve it, maybe this example fits your goal? Because you can redirect to an url, but you may also do it by calling the view... https://www.tutorialspoint.com/django/django_page_redirection.htm – DA-- Jul 02 '17 at 12:11

0 Answers0