Reputation: 45
Help! I have a simple problem.
I made links in my templates, like this:
<a href="students">students</a>
When i go to alumni.html and i click on the link directing to students.html, it directs to alumni/students
but i want to click and see /students.
I dont understand why its routing to alumni/students instead.
I only changed one aspect of settings.py into: 'DIRS': [os.path.join(BASE_DIR, "templates")],
urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^students/$', 'assignments.views.students', name='students'),
url(r'^alumni/$', 'assignments.views.alumni', name='alumni'),
]
views.py
from django.shortcuts import render
def students(request):
return render(request, "students.html", {})
def alumni(request):
return render(request, "alumni.html", {})
What am i doing wrong?
Upvotes: 2
Views: 40
Reputation: 27543
change the url in the template to this
<a href="{% url 'students' %}">students</a>
Upvotes: 1