Reputation: 95
I have spent so much time trying to solve this issue but don't know where the problem lies since there are no errors popping up. It simply doesn't work.
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
Home/
templates/
Home/
Home.html
Application/
templates/
Application/
Apply.html
In my Home.html I have a link:
<a href="{% url 'Application:Apply' %}">Apply Now!</a>
When I click on it, the url changes to /Apply but I remain on the same page. (It also seems like the Home.html is getting reloaded since I need to scroll down the page to click on that link and once I click it, it gets me back to the top of the page).
mysite/urls.py
from django.conf.urls import url, include
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('Application.urls', namespace = 'Application')),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,
document_root=settings.STATIC_ROOT)
Home/urls.py
from django.conf.urls import url, include
from . import views
urlpatterns = [
url(r'^', views.Home, name = 'Home'),
]
Application/urls.py
from django.conf.urls import url, include
from . import views
app_name = "Application"
urlpatterns = [
url(r'Apply', views.Apply, name = 'Apply'),
]
Application/views.py
from django.shortcuts import render
def Apply(request):
return render(request, 'Application/Apply.html')
I would greatly appreciate any advice since I cannot move on with my project until I figure that out.
Upvotes: 1
Views: 440
Reputation: 78556
You're missing the end-of-string character '$'
in your Home
url, so the pattern intercepts every other url since they all match the start character '^'
. Add an end-of-string character:
urlpatterns = [
url(r'^$', views.Home, name = 'Home'),
]
Demo:
>>> import re
>>> re.match('^', 'Apply')
<_sre.SRE_Match object at 0x1034c9b90>
>>> re.match('^$', 'Apply')
>>>
Upvotes: 5