开发者

Serving Django application from relative path

I am developing a Django application which works fine locally. In production, the application will be served from a relative path, such as www.example.com/app/.

I am using Apache with mod_wsgi, and I have configured Apache to serve the application from the relative URL:

WSGIScriptAlias /app /path/to/my/modwsgi.py
WSGIDaemonProcess app display-name=app_wsgi

Unfor开发者_高级运维tunately, I get an Error 404. The debug information, though, is pretty mysterious. If I try to get www.example.com/app/myurl/, Django says

Using the URLconf defined in apps.urls, Django tried these URL patterns, in this order:

    ^myurl/$
    ...

The current URL, myurl/, didn't match any of these.

It seems that Django - correctly - infers that the path requested is myurl/, and not app/myurl/. But, even though myurl/ clearly matches ^myurl/$, it does not find a match.

I have also tried to add the setting

FORCE_SCRIPT_NAME = '/app'

but nothing changes - the error message remains identical.


The debug information lies :-/ Trying with more permissive regexs in the URL conf; iwas able to get a page. From there I could print request.path, and it turned out to be app/myurl/.

To make it work, I had instead to put

FORCE_SCRIPT_NAME = ''
STATIC_URL = '/app/static/'
MEDIA_URL = '/app/media/'
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜