Note that there are some explanatory texts on larger screens.

plurals
  1. POtrailing slash "/" not added to root url
    text
    copied!<p>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</p> <pre><code>www.example.com/subdir </code></pre> <p>is not being directed to </p> <pre><code>www.example.com/subdir/ </code></pre> <p>urls.py looks like this:</p> <pre><code>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&lt;pk&gt;\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')}), ) </code></pre> <p>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.</p> <p>Can you suggest a way to do this with django, or is this a problem with apache and not django</p> <p>EDIT 1: APPEND_SLASH is not set to false.</p> <p>Also httpd.conf also has this:</p> <pre><code>&lt;VirtualHost *:80&gt; DocumentRoot /var/www/html ServerName example.cm WSGIScriptAlias /subdir /var/www/html/cloudcv/apache/django.wsgi &lt;Directory /var/www/html/cloudcv&gt; Order allow,deny Allow from all &lt;/Directory&gt; &lt;/VirtualHost&gt; </code></pre> <p>settings.py has this:</p> <pre><code>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 </code></pre> <p>Also to make things more clear, the append slash is working fine when I put like <strong>r'^new$'</strong> instead of <strong>r'^$'</strong> and the file directory structure is like this:</p> <pre><code>- /var/www/html/cloudcv/ + apache -fileupload urls.py views.py &lt;other files&gt; settings.py &lt;other files&gt; </code></pre> <p>here "other files" means other files of the directory</p> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload