开发者

Apache | Django: How to run websites on the back of a base URL?

I've got a base url. http://baseurl.com/ I'm trying to run projects on the back of it. For example http://baseurl.com/mongoose/ The projects run but the URL don't work properly because they all reference the base url. So for 'About Me' page it points to http://baseurl.com/about instead of http://baseurl.com/mongoose/about

Is this something i need to change in django or开发者_运维知识库 apache? Is what I'm trying to do even possible?

Coming from an IIS .net background I know that in IIS you can "Create and application" within a site which essentially does what I'm trying to achieve now with Apache and Django.

Thanks


You shouldn't need to do anything. Apache is supposed to be setting a request header called SCRIPT_NAME, which is your base URL, and all URL reversing takes that into account.

How are you creating these URLs in your templates?

Update

So your problem is with getting the URLs of Flatpages. The issue is that the normal way of calculating URLs dynamically, so that they do take SCRIPT_NAME into account - using the reverse() function or the {% url %} tag - doesn't work with Flatpages, because they are not dispatched via urls.py but via a custom middleware which fires on a 404.

So instead of using that middleware, I would use the urls.py mechanism to dispatch to flatpages. Remove the flatpagemiddleware from your settings.py, and in urls.py at the end of your patterns add this:

url(r'^(?P<url>.*)$', 'django.contrib.flatpages.views.flatpage', name='flatpage'), 

Now, in your templates, you can do:

<a href="{% url flatpage page.url %}">

and it should work correctly.


Check any urls.py in the project(s) to see if they expect to be top-level. But if the application outputs links like /something then it's going to mean the root directory. The application should be reversing a view/parameter into a URL, which would allow you to move it around. If you wrote the apps, check out reverse in django.core.urlresolvers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜