Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Change root url in application

I have a working application/system (Python 3.9, Django 3.1) on my server. Now I need to move it to another server with an alias.

From this www.myserver.com to this www.otherserver.com/myapp.

In Apache2 config I have line WSGIScriptAlias /myapp /path/to/myapp/wsgi.py. But now I have a problem with all links in app, e.g. link from index page to catalog page redirects to www.otherserver.com/catalog but I need www.otherserver.com/myapp/catalog.

  • Is there any feature in Django?
  • Is it possible to set just some global variable in settings.py?
  • Do I need to edit all the links in the templates?

What is the best solution?

like image 999
Martin Special Avatar asked Sep 01 '25 20:09

Martin Special


1 Answers

A quick way is to include the projects url patterns at the new path.

Make a new patterns list, e.g. base_patterns

base_patterns = [
    path('admin/', admin.site.urls),
    path('app/', include('app.urls),
]

At the bottom of the main urls.py include the base_patterns at the new path.

urlpatterns = [
    path('catalog/', include(base_patterns)),
]
like image 196
Michael Lindsay Avatar answered Sep 03 '25 10:09

Michael Lindsay