django NoReverseMatch Exception


django NoReverseMatch Exception



I'm getting the following error while using hyperlink in Django.



Error:



django.urls.exceptions.NoReverseMatch: 'mywebapp' is not a registered namespace


django.urls.exceptions.NoReverseMatch: 'mywebapp' is not a registered namespace



mywebapp/template/about.html ..


<body>
<a href="{% url 'mywebapp:home' %}">Click here</a>
Hello World!!!<p>Today is {{today}}</p>





mywebapp/template/home.html ..


<h4>Homepage.</h4>



settings.py ..


INSTALLED_APPS =
[
...
'mywebapp'#new
...
]





Make sure you have app_name='home' in your mywebapp/urls.py. If that doesn’t solve the problem, then you need to show your urls.py.
– Alasdair
Jun 30 at 20:20


app_name='home'


mywebapp/urls.py


urls.py





Please show us your urls.py – thanks
– mrehan
Jun 30 at 20:36


urls.py




1 Answer
1



In you urls.py of the mywebapp app, make sure you have:


urls.py


mywebapp


app_name = 'mywebapp'

urlpatterns = [
re_path(r'REGEX_HOME', YOUR_HOME_VIEW, name='home'),
# or if you're not using regex
# path('HOME_PATH', YOUR_HOME_VIEW, name='home'),
# for Django 1.11
# url(r'REGEX_HOME', YOUR_HOME_VIEW, name='home'),
]



Substitute REGEX_HOME and YOUR_HOME_VIEW with your own values.


REGEX_HOME


YOUR_HOME_VIEW






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

List of Kim Possible characters

Audio Livestreaming with Python & Flask