1đź‘Ť
Finally I found the error. It was not connected to httpd.conf file but to how URLs are specified both to django urls.py file and to templates.
As I mounted myapp in this way:
WSGIScriptAlias /myapp my_path_to_wsgi_module/django.wsgi
I was believing that URLs specified in django template files should carry an initial slash, like this:
'/api/dir'
It results that in this way the application works only on django development server but not on apache.
Instead if you use URLs without initial slash like:
'api/dir'
The app works correctly both on django development server and on apache!
You must avoid using starting slashes even on pattern matching of django urls.py file:
like this: (r'^api/dir$', 'available_services')
and NOT like this: (r'^/api/dir$', 'available_services')
Maybe this is an obvious thing for expert django users but if you’re novice like me, this can make you loose a certain amount of time because it’s a hard problem to be detected.
1đź‘Ť
It appears you are missing some things from your apache config:
In the working config for my server I have:
# tell apache where to find the wsgi script.
WSGIScriptAlias / "/home/path_to_my_app/wsgi/my.settings.wsgi"
# turn on auto-reload in WSGI
WSGIScriptReloading On
WSGIReloadMechanism Process
# assign a process to a process group
WSGIDaemonProcess djangoapps processes=10 threads=1 maximum-requests=500 display-name=my-wsgi
WSGIProcessGroup djangoapps
Your WSGIScriptAlias line is correct but you need to tell wsgi how you are going to run your application.
You are most likely getting 404’s because there is not a WSGIDaemonProcess line to tell the WSGI handler how to work with your process.
http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives might be a helpful reference.
- [Answered ]-Django formset apparently only printing first form in template (because of invalid markup)
- [Answered ]-Check if object on foreign key is set
- [Answered ]-Django dict in template
- [Answered ]-What is a proper way to implement a state engine with asynchronous events?
- [Answered ]-How to limit choices to Foreign keys in Django admin
0đź‘Ť
Actually it is a bit more complicated than just that.
There are some times when you need absolute in-app urls, because you don’t want to reach an url which is relative to the current url.
e.g. you have a global menu in a main layout template (i.e. a template which is “extend”ed by each other template in your project): you cannot have relative urls like “home”, “contact”, “about”, “blog” because if you are in /yourapp/blog/entries/2014/02/06/add (let’s say such url exist) and you click any menu item, you would go to (say, for “home”) /yourapp/blog/entries/2014/02/06/add/home instead to /home, which you would expect.
The ugly solution of virtual hosts is good here (in Java, Struts 2 has an option to resolve urls for “actions” (i.e. named urls / entry points) including the deploy context directory as deployed in the web container (e.g. tomcat)) … don’t know it there’s any “context” setting you can guess (perhaps it’s possible to return the current “WSGIScriptAlias” key as an environment variable). After that, using back the initial slash for urls (“/home”).
- [Answered ]-How can I close a django 1.8 database cursor and connection?
- [Answered ]-Fetching related parent objects in a chain in Django
- [Answered ]-Initiating a method in a class