Solutions of Django URLResolver error
Add ROOT_URLCONF Setting
This is the important configuration setting need to define in settings.py file that specifies base directory where you have defined the urls that will route the request in your project apps.
ROOT_URLCONF = 'myproject.urls'
Fix URL Patterns and Views
Hit below command “python manage.py check app_name“. after hitting this command Django will check if there are any issues are there in mentioned app name. if there is any it will show the error line number with the problem. The next step would be go and fix the problem at the indicated place.
Add Static/Media files settings
if you are using static urls or media files urls in your project. for this purpose you need to have this line in your root urls.file.
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
# ... the rest of your URLconf goes here ...
]
urlpattern += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpattern += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Clear Cache And Restart the Server
Try below commands to clear out the cache and restart the server.
The ‘python manage.py flush'
command is used in Django to reset the database by removing all data from it. It is a management command provided by Django’s management system and can be executed in the terminal.
python manage.py flush
Hope, you may find this article helpful. I will update the article when there will be more solutions available for this.
Django URLResolver error
There are many errors that come when we create a project in Django. In this article, we will learn how to resolve such error “URLResolver error”.
Contact Us