I have a problem that Django automatically adds slash to urls that ends with ".htm"
Url like:
http://127.0.0.1:8080/js/tiny_mce/themes/advanced/link.htm
becomes:
http://127.0.0.1:8080/js/tiny_mce/themes/advanced/link.htm/
But if I rename "link.htm" to "link.html" then no problem happens.
Where could be the issues?
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_downloa开发者_如何学Cd_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"),
)
Django has a setting, "APPEND_SLASH", which adds a slash to URLs that are not otherwise matched in the URLConf, but would be matched if a slash were added. So you probably have some regex pattern in your urls.py that is matching ".htm/".
It looks like you are using Django to serve static files? If so, you might make sure this is configured properly. 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 settings.py:
# 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}),
)
精彩评论