Open kravietz opened 11 years ago
I encountered the same problem. To fix it for now, I edit the dajaxice.core.js file after being created.
It can be solved, if when creating the JS file, it will generate the endpoint according to DAJAXICE_MEDIA_PREFIX and not according to the URLdispacher.
I've just test DAJAXICE_MEDIA_PREFIX
and it works. Could you please share which version of dajaxice are you using?
I'm using 0.5.5
The settings property works, but the problem still occurs:
the Django app is configured in Apache under some path: lets say "myapp" Django doesn't know about it and doesn't care..
So, all the requests to the Dajaxice service should be relative to "myapp" from now on. (because the requests are from client side)
if I change the DAJAXICE_MEDIA_PREFIX
to 'myapp/dajaxice' it generates the dajaxice app's urls under 'myapp/dajaxice'.
But now, to access dajaxice I need to access http://mydomain.com/myapp/myapp/dajaxice....
first myapp - apache second myapp - django
The property I'm looking for is a prefix that will be added only to the JS file. (maybe you can think about a more appropriate solution)
I was experiencing the same issue here and finally found out what was wrong.
The problem is: when the var endpoint
is generated (with manage.py collectstatic
), django is not being served by apache.
If the django project is being served by apache on the "root" (e. g., example.com), everithing should work nicely. However, if django is being served on a "subdir" (e.g., example.com/subdir) then the problem will show up, because while the endpoint will point to '/dajaxice...', django will be serving it on '/subdir/dajaxice...'
To fix this, I generated the url in the templatetag. I don't know if this is the best solution, but at least it wont require manual edition of the JS file.
Since the author discontinued the project, I'll simply point out the files to be changed (the original lines to be changed are commented):
dajaxice/templatetags/dajaxice_templatetags.py
# return '<script src="%s" type="text/javascript" charset="utf-8"></script>' % url
template_tag = "<script type='text/javascript'>var dajaxice_endpoint = '%s'</script>\n" % reverse('dajaxice-endpoint')
url = staticfiles_storage.url('dajaxice/dajaxice.core.js')
template_tag += '<script src="%s" type="text/javascript" charset="utf-8"></script>' % url
return template_tag
dajaxice/templates/dajaxice/dajaxice.core.js
// endpoint = '{% url 'dajaxice-endpoint' %}'+dajaxice_function+'/';
endpoint = dajaxice_endpoint+dajaxice_function+'/';
I sent those changes to this fork of the project
I'm using Django on URL like http://domain/sub where all requests to sub/ are passed to Django. Everything works fine except for Dajaxice calls. I have added the following to settings.py:
DAJAXICE_MEDIA_PREFIX='xxx/dajaxice'
But dajaxice.core.js is generated with absolute path:
var send_data = 'argv='+encodeURIComponent(JSON.stringify(argv)), oXMLHttpRequest = new XMLHttpRequest, endpoint = '/dajaxice/'+dajaxice_function+'/';
As result Dajaxice requests hit non-existent URL on the main site (/dajaxice) while they should be going to /xxx/dajaxice.