Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding an aliasName for url name app django

In a django project, I have an app : app_signup.

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'app_signup',

app_signup/urls.py

from django.urls import path, include
from . import views

urlpatterns = [
    path('',views.index, name='index'),
]

Is it possible to add an alias to the app in order to see the alias (http://localhost:8000/alias/) instead of the name of the app(http://localhost:8000/app_signup/) in the url on the browser.

like image 915
QDex Avatar asked Dec 21 '25 08:12

QDex


2 Answers

The name of the app in INSTALLED_APPS doesn't really matter. Your project's main urls.py file is the one that specifies the path. There when constructing the urlpatterns list, you can do path('alias/', include('app_signup.urls')) instead of path('app_signup/', include('app_signup.urls')).

like image 186
shriakhilc Avatar answered Dec 24 '25 11:12

shriakhilc


As far as I understand from the example you added, you are editing the urls.py file within the app you created. Not your app, but directly in the project file (in the same directory as settings.py), urls.py probably as path('app_signup/', include('app_signup.urls')) as mentioned in the answer above. This is the urls.py you need to edit.

like image 22
ImErtekin Avatar answered Dec 24 '25 10:12

ImErtekin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!