Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Site-Wide URL Prefix

I've built a Django site that will live at the root when it's live. Right now it's functioning perfectly at the IP address. For testing purposes, the client has pointed a proxy url at it, but the url has /folder/path in it, so none of the URL patterns match. I put (/folder/path)? into all the url patterns so they now respond, but all of the links are broken because I'm using the {% url %} tag and while the url patterns will match the optional path, they don't include it in that tag.

Clearly I can just hard-code /folder/path into all of my urls (well, into all of the url includes) until testing is complete, but is there a better way to do this?

like image 473
Tom Avatar asked May 24 '10 15:05

Tom


People also ask

What are url converters in Django?

Setting Converters in URLS The converters are responsible for converting a dynamic value in the URL to a needed value format. The below example shows how the url value can be converted to a string format and passed into its corresponding view. 5. Creating a Django URL Through URL ()

How do I use regular expressions in Django url?

Creating a Django URL USING RE_PATH () The re_path () method allows the use of python regular expressions in URLs. This was introduced in version 2.0 along with the path () method. Note: The question mark in regex allows the indexes page to get loaded with only the index mentioned in it.

What is the well-known URL prefix?

The /.well-known/ URL path prefix is a reserved name space for serving particular static files used by other systems that might interact with your site. It was established by RFC 5785 and updated in RFC 8615 .

How do I access a website from a Django app?

The technique involves creating url patterns within each app. This will bring more flexibility when the app needs to be plugged into a different application. Just making inclusion of these URL’s in the main project urls.py file will help to easily access the web pages associated with that Django application.


1 Answers

You manage this when you deploy your application, by correctly setting the WSGIScriptAlias in your Apache configuration (assuming you're using mod_wsgi, which you should be doing). This is passed on to Django, which then automatically prefixes all URL reverse lookups with the correct value. You shouldn't need to do any manual mucking about with prefixes.

like image 191
Daniel Roseman Avatar answered Oct 17 '22 13:10

Daniel Roseman