I recently came across a very strange problem I could not resolve. I am running django with mod_wsgi and apache, and the problem is that
www.example.com/subdir
is not being directed to
www.example.com/subdir/
urls.py looks like this:
import os
from django.conf.urls.defaults import *
from fileupload.views import PictureCreateView, PictureDeleteView
urlpatterns = patterns('',
(r'^$', PictureCreateView.as_view(), {}, 'upload-new'),
(r'^delete/(?P<pk>\d+)$', PictureDeleteView.as_view(), {}, 'upload-delete'),
(r'^fileupload/media/(.*)$', 'django.views.static.serve',
{'document_root':os.path.join(os.path.abspath(os.path.dirname(__file__)),'media')}),
)
It is kinda important for me to put a trailing slash at the end. I tried putting .htaccess in the folder, but then it only works with firefox and not google chrome.
Can you suggest a way to do this with django, or is this a problem with apache and not django
EDIT 1: APPEND_SLASH is not set to false.
Also httpd.conf also has this:
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName example.cm
WSGIScriptAlias /subdir /var/www/html/cloudcv/apache/django.wsgi
<Directory /var/www/html/cloudcv>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
settings.py has this:
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'fileupload.urls'
APPEND_SLASH = true
Also to make things more clear, the append slash is working fine when I put like r'^new$' instead of r'^$' and the file directory structure is like this:
- /var/www/html/cloudcv/
+ apache
-fileupload
urls.py
views.py
<other files>
settings.py
<other files>
here "other files" means other files of the directory
UPDATE 1: orokusaki pointed out a new error in the upload-delete url and he updated his answer to correct. Just pointing that out because it might be helpful to others who reach this answer.