For the case of get_static_prefix, what do you have MEDIA_URL set to
in Django settings file?
My understanding is that the URL specified by that setting is absolute
and SCRIPT_NAME prefix from WSGI environ dictionary representing the
mount point of the application is not automatically inserted. So, the
mount points needs to be inserted into MEDIA_URL manually. As this is
new to Django 1.3 I could be wrong about that though.
Other settings where similarly it is necessary to insert mount point
manually are LOGIN_URL and LOGOUT_URL. I am not sure though about
redirect().
The url template tag is supposed to add SCRIPT_NAME prefix
automatically however.
One thing you can do is at least verify what SCRIPT_NAME is being set
to. You would see this in error pages if DEBUG is True. Alternatively
you can replace Django WSGI script file with script from:
http://code.google.com/p/modwsgi/wiki/DebuggingTechniques#Displaying_Request_Environment
which will show what the WSGI environ is back into browser so can do
sanity checks on what SCRIPT_NAME is.
Graham
On 11 July 2011 09:12, Alex Hung <[email protected]> wrote:
> Hi,
>
> I've been banging my head against this problem for a few days now, and
> haven't been able to find any solution. I have a Django app deployed
> to apache at a sub url mounting point ('/myproject') and I have no
> problem access the app. However, when I use {% get_static_prefix %} in
> my template to reference javascript file, the path that Django spits
> out is "/static/js/myscript.js". What I'm expecting is "/myproject/
> static/js/myscript.js", i.e. Django takes the WSGIAlias into account.
>
> Note that this problem is not restricted to static file. Any Django
> function that utilises reverse() (e.g. redirect()) also error out with
> NoReverseMatch exception for the same reason.
>
> Have I missed a glaring config error? All the documentations (Django,
> mod_wsgi, etc.) say this configuration should "just work". But instead
> I found it never work.
>
> TIA,
> Alex
>
> =========
>
> Apache conf
> ------------------
>
> WSGIScriptAlias /directory "/Library/WebServer/Documents/apache/
> django.wsgi"
>
> LogLevel info
> ErrorLog /Library/WebServer/Documents/apache/error.log
>
> <Directory "/Library/WebServer/Documents/apache">
> Order allow,deny
> Allow from all
> </Directory>
>
> wsgi script
> ----------------
>
> import os
> import site
> import sys
>
> sys.stdout = sys.stderr
>
> # Remember original sys.path.
> prev_sys_path = list(sys.path)
>
> site_dir = '/Library/WebServer/Documents/apache/virtual_env/lib/
> python2.7/site-packages'
> site.addsitedir(site_dir)
>
> apache_configuration = os.path.dirname(__file__)
> project = os.path.dirname(apache_configuration)
> workspace = os.path.dirname(project)
> sys.path.append(project)
> sys.path.append(workspace)
> sys.path.append('/Library/WebServer/Documents/')
> sys.path.append('/Library/WebServer/Documents/myproject')
>
> # Reorder sys.path so new directories at the front.
> new_sys_path = []
> for item in list(sys.path):
> if item not in prev_sys_path:
> new_sys_path.append(item)
> sys.path.remove(item)
> sys.path[:0] = new_sys_path
>
> os.environ['PYTHON_EGG_CACHE'] = '/Library/WebServer/Documents/apache/
> python-eggs'
> os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
>
> import django.core.handlers.wsgi
> application = django.core.handlers.wsgi.WSGIHandler()
>
> --
> You received this message because you are subscribed to the Google Groups
> "modwsgi" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/modwsgi?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/modwsgi?hl=en.