Why does Django automatically add a slash after the URL that ends with ".htm" and not when the URL ends with ".html"?

I have a problem where Django automatically adds a forward slash to URLs ending with ".htm"

URL: http://127.0.0.1:8080/js/tiny_mce/themes/advanced/link.htm

Will look like this: http://127.0.0.1:8080/js/tiny_mce/themes/advanced/link.htm/

But if I rename the link "link.htm" to "link.html" then there will be no problem.

Where can there be problems?

Thanks.

urls.py:

from django.conf.urls.defaults import *
from dtunes.views import *
from django.conf import settings
from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',

    url(r'^$', home, name='home'),

     url(r'^(?P<path>.*\.(htm|html|jpg|jpeg|css|gif|js|png))$', "django.views.static.serve", {
            "document_root": settings.MEDIA_ROOT,
        }, name="media"),

    url(r'^img/tr.gif', track, name='track'),
    (r'^admin/', include(admin.site.urls)),
    url(r'^smscoin/ipn/', ipn, name='smscoin_ipn'),
    url(r'^download-link/', get_download_link, name='get_download_link'),
    url(r'^get/(?P<name>.*)/$', item_details, name="item_details"),
    url(r'^getnow', item_details_paid, name="item_details_paid"),
    url(r'^download/(?P<name>.*)/$', send_direct_file, name="send_direct_file"),
    url(r'^(?P<name>.*)/$', plain_page, name="plain_page"),       

)

      

+2


a source to share


1 answer


Django has an "APPEND_SLASH" parameter that adds a forward slash to URLs that would not otherwise match in URLConf, but would if a forward slash was added. So you probably have some regex pattern in your urls.py that matches ".htm /".

Sounds like you're using Django to serve up static files ? If so, you can verify that it is configured correctly. During development, to keep things DRY, I usually use the following in my "urls.py" file to serve static media. This requires a properly configured MEDIA_ROOT and MEDIA_URL in the .py settings:



# urls.py
from django.conf import settings

urlpatterns = patterns(
   ...
)

if settings.DEBUG:
    urlpatterns += patterns('',
            (r'^%s/(?P<path>.*)$' % settings.MEDIA_URL[1:-1],
                'django.views.static.serve',
                {'document_root': settings.MEDIA_ROOT}),
    )

      

+2


a source







All Articles