Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set base URL in Django

I would like to run Django from location https://www.example.com/someuri/ so that I have the admin interface at https://www.example.com/someuri/admin/. I can see the login window but when I log in I get redirected to https://www.example.com/admin/.

Where can I set the base URL of Django to https://www.example.com/someuri/? I tried with BASE_URL but with no luck.

like image 259
sposnjak Avatar asked Jul 02 '13 08:07

sposnjak


People also ask

How can I get full URL in Django?

Use handy request. build_absolute_uri() method on request, pass it the relative url and it'll give you full one. By default, the absolute URL for request. get_full_path() is returned, but you can pass it a relative URL as the first argument to convert it to an absolute URL.

What is URL configuration in Django?

In Django, views are Python functions which take a URL request as parameter and return an HTTP response or throw an exception like 404. Each view needs to be mapped to a corresponding URL pattern. This is done via a Python module called URLConf(URL configuration) Let the project name be myProject.

What is absolute URL Django?

To get the full or absolute URL (with domain) in Python Django, we can use the build_absolute_uri method. request.build_absolute_uri(reverse('view_name', args=(obj.pk, ))) to call request. build_absolute_uri with reverse('view_name', args=(obj.pk, ) to get the path of the view with reverse . Then we call “request.


1 Answers

@AgileDeveloper's answer is completely correct for that one off case of admin. However, is the desire to set it this way for all URLs? If so, perhaps you should do something like this

from django.conf.urls import include, url
from . import views

urlpatterns = [
    url(r'^someuri/', include([
        url(r'^admin/', include(admin.site.urls) ),
        url(r'^other/$', views.other)
    ])),
]
like image 113
raiderrobert Avatar answered Sep 20 '22 09:09

raiderrobert