Search code examples
djangodjango-urlsapplication-settings

Django: What is the simplest way to shorten the application url?


I have a Django application that has a long name "encyclopedia". I would like the url for the application that appears on the address bar to be something shorter like "http://127.0.0.1:8000/ency" instead of "http://127.0.0.1:8000/encyclopedia" . What is the simplest way to accomplish this without compromising the functionality of the application?

I suspect its something very simple like modifying ROOT_URLCONF in settings.py. There is a general lack of examples that illustrate how to in the documents.


Solution

  • Assuming you have a separate urls.py file for the Django application "encyclopedia", simply include it as follows in the main urls.py file of your project:

    from django.urls import path, include
    
    urlpatterns = [
        path('admin/', admin.site.urls),
        path('ency/', include('encyclopedia.urls')),
    ]