1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # In your settings.py
URL_PREFIX = "/subdirectory"
# At the bottom of your urls.py
# Prefix all the above patterns with URL_PREFIX
# Note: All urls must begin with ^, and URL_PATTERN must begin with /
if settings.URL_PREFIX:
prefixed_urlpattern = []
for pat in urlpatterns:
pat.regex = re.compile(r"^%s/%s" % (settings.URL_PREFIX[1:], pat.regex.pattern[1:]))
prefixed_urlpattern.append(pat)
urlpatterns = prefixed_urlpattern
|
More like this
- django subdomain support for both resolve and reverse. by puppy 2 years, 11 months ago
- Easy configuration for relocatable sites by gsakkis 2 years, 9 months ago
- Link raw_id_fields (both ForeignKeys and ManyToManyFields) to their change pages by EmilStenstrom 2 years, 7 months ago
- Serve static media files from app/media subdirectory by adamlofts 4 years, 9 months ago
- direct to template from a subdir by Scanner 4 years, 7 months ago
Comments
I suggest another way, which is simpler and more pythonic IMHO.
In your
urls.pyrenameurlpatternstobase_urlpatterns; then add the followinig definition at the end of the same file:#
@lallulli: I agree, your solution is much better!
#