DaithiOK
DaithiOK

Reputation: 135

I can't get my Django URLs to work

My code is as follows:

root urls.py

from django.conf.urls import include, url
from django.contrib import admin


urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'', include('app.urls')),
]

My applications url is like so

urlpatterns = [
    url(r'^$',views.login, name='login'),
    url(r'^homepage/$', views.homepage, name='homepage'),
]

The first screen the user will see is the login screen (views.login). At the moment I just want to set the login button to be a url that takes them to the homepage (just for practice) but it doesnt seem to work.

The login html is like so

<button type="button"><a href="{% url 'homepage' %}">Log-In</a></button>

This should go to my urls page above...find the name 'homepage' and take me to views.homepage which is as so:

def homepage(request):
    return render(request, 'application/homepage.html', {})

but my homepage doesnt get rendered and I have absolutely no idea why its driving me crazy.

Any help would be appreciated.

Upvotes: 1

Views: 113

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599460

This is nothing to do with Django, but a pure HTML problem. You can't put a link inside a button. A button needs to be part of a form, and submits to the action value of that form. Either do that, and take the a tag out; or, remove the button, and just use the a.

Upvotes: 1

Related Questions