When I go to http://localhost:8000/getAndAnalyzePosts/index
it 404s and adds a trailing slash (it does this regardless of whether I have APPEND_SLASH = True
or APPEND_SLASH = False
Going to http://localhost:8000/getAndAnalyzePosts/test
doesn't work but http://localhost:8000/getAndAnalyzePosts/test.anything
does.
I really want to use '^$'
for the index but that isn't working either.
I have this app in a mezzanine project, I haven't tried putting it into a regular django project - probably should do that next. The rest of my project works fine (using mezzanine's default apps)
getAndAnalyzePosts/urls.py
from django.conf.urls import patterns, url
from getAndAnalyzePosts import views
urlpatterns = patterns('',
url(r'^index$', views.index, name='index'),
url(r'^test.+$', views.test, name='test'),
url(r'^getSentiment$', views.getSentiment, name='getSentiment'),
)
note: getSentiment wants post variables so I am not really testing that directly
urls.py (main project)
from __future__ import unicode_literals
from django.conf.urls import patterns, include, url
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from mezzanine.core.views import direct_to_template
admin.autodiscover()
urlpatterns = i18n_patterns("",
("^admin/", include(admin.site.urls)),
)
urlpatterns += patterns('',
url(r"^$", direct_to_template, {"template": "index.html"}, name="home"),
(r"^", include("mezzanine.urls")),
url(r'^getAndAnalyzePosts/', include('getAndAnalyzePosts.urls', namespace="getAndAnalyzePosts")),
)
handler404 = "mezzanine.core.views.page_not_found"
handler500 = "mezzanine.core.views.server_error"
Also, I run python manage.py show_urls
from django-extensions and it returns:
/getAndAnalyzePosts/getSentiment getAndAnalyzePosts.views.getSentiment getSentiment
/getAndAnalyzePosts/index getAndAnalyzePosts.views.index index
/getAndAnalyzePosts/test.+ getAndAnalyzePosts.views.test test
The project urls.py you've pasted here at some stage had some comments in great big capital letters describing the exact problem you're facing, here's their original source:
https://github.com/stephenmcd/mezzanine/blob/master/mezzanine/project_template/urls.py#L63-L66
Append slash option makes sure that if the incoming url does not have trailing slash and no url gets match, then it retires after adding trailing slash. What it does not do is retry after removing trailing slash from incoming url. Since incoming url does have a trailing slash, you need a / before $ Add / at the end, before $ in all your urls, (r'^getSentiment/$) Let append slash be true and it should work.
.+ works because . in regex matching anything except newline and you added + after it so it matches any character any number of times, to match . exactly you need to escape it (.) Making it ^text\..+$
When I go to http://localhost:8000/getAndAnalyzePosts/index
it 404s and adds a trailing slash (it does this regardless of whether I have APPEND_SLASH = True
or APPEND_SLASH = False
Going to http://localhost:8000/getAndAnalyzePosts/test
doesn't work but http://localhost:8000/getAndAnalyzePosts/test.anything
does.
I really want to use '^$'
for the index but that isn't working either.
I have this app in a mezzanine project, I haven't tried putting it into a regular django project - probably should do that next. The rest of my project works fine (using mezzanine's default apps)
getAndAnalyzePosts/urls.py
from django.conf.urls import patterns, url
from getAndAnalyzePosts import views
urlpatterns = patterns('',
url(r'^index$', views.index, name='index'),
url(r'^test.+$', views.test, name='test'),
url(r'^getSentiment$', views.getSentiment, name='getSentiment'),
)
note: getSentiment wants post variables so I am not really testing that directly
urls.py (main project)
from __future__ import unicode_literals
from django.conf.urls import patterns, include, url
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from mezzanine.core.views import direct_to_template
admin.autodiscover()
urlpatterns = i18n_patterns("",
("^admin/", include(admin.site.urls)),
)
urlpatterns += patterns('',
url(r"^$", direct_to_template, {"template": "index.html"}, name="home"),
(r"^", include("mezzanine.urls")),
url(r'^getAndAnalyzePosts/', include('getAndAnalyzePosts.urls', namespace="getAndAnalyzePosts")),
)
handler404 = "mezzanine.core.views.page_not_found"
handler500 = "mezzanine.core.views.server_error"
Also, I run python manage.py show_urls
from django-extensions and it returns:
/getAndAnalyzePosts/getSentiment getAndAnalyzePosts.views.getSentiment getSentiment
/getAndAnalyzePosts/index getAndAnalyzePosts.views.index index
/getAndAnalyzePosts/test.+ getAndAnalyzePosts.views.test test
The project urls.py you've pasted here at some stage had some comments in great big capital letters describing the exact problem you're facing, here's their original source:
https://github.com/stephenmcd/mezzanine/blob/master/mezzanine/project_template/urls.py#L63-L66
Append slash option makes sure that if the incoming url does not have trailing slash and no url gets match, then it retires after adding trailing slash. What it does not do is retry after removing trailing slash from incoming url. Since incoming url does have a trailing slash, you need a / before $ Add / at the end, before $ in all your urls, (r'^getSentiment/$) Let append slash be true and it should work.
.+ works because . in regex matching anything except newline and you added + after it so it matches any character any number of times, to match . exactly you need to escape it (.) Making it ^text\..+$
0 commentaires:
Enregistrer un commentaire