I have just installed Django Page CMS, which looks quite promising for a certain problem i have right now. After reading through the docs at packages.python.org, and doing the described settings, i got it to appear in the admin interface. But as soon as i try to add a page, i get that error message:
TemplateSyntaxError at /admin/pages/page/
Caught NoReverseMatch while rendering: Reverse for 'pages-details-by-path' with arguments '(u'faq',)' and keyword arguments '{}' not found.
As i assume this has something to do with my url configuration, here is the lines that include the django page cms urls:
urlpatterns+= patterns('',
(r'', include('pages.urls')),
)
I have not worked too much with reverse url lookups yet, and page cms is completely new to me, so i would be glad if someone could point me in the right direction.
edit:
Stupid - i have got a seperate dev_url.py for development. Have been working for two weeks on the production server and just forgot about it. The code above works perfectly well.
The URL pattern you included is matching everything- including admin, which I don't believe you're supposed to. According to the django-page-cms docs urls.py should look like:
urlpatterns = patterns('',
url(r'^pages/', include('pages.urls')),
(r'^admin/', include(admin.site.urls)),
)
Related
The index site on my Django homepage stopped working because of a problem that will take a very long time to fix. The site can't be down for that long so I am trying to change the index site so that if you go to the primary url you will atleast end up on the website.
What I have done is change the urls.py file in the primary application, where I simply replaced the line
url(r'^', include('news.urls', namespace='news')),
to
url(r'^', include('events.urls', namespace='events')),
in the urlpatterns list, where news is the faulty page and events is the page that I want to be shown. However, after pushing this to live nothing changed, and for some reason my local Django development server is not working.
Did I do anything wrong, or is there anything else I have to do as well?
Thanks.
In the events app make sure you have a URL such as
......
url(r'^$', views.EventsIndex.as_view(), name='index'),
......
Replacing news.urls with events.urls may cause problems, if there are views/templates that try to reverse news urls. It would be better to leave the include as it is, and add a new URL pattern above that for the index:
from events.views import home
urlpatterns = [
url(r'^$', home, name='home'),
url(r'^', include('news.urls', namespace='news')),
...
]
Previous working configuration of urls.py:
I'm not using include. Previously, a configuration of the project's url.py like this has worked perfectly for me:
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^$', 'projectName.appName.views.view1'),
url(r'^about/$', 'projectName.appName.views.view2'),
url(r'^contact/$', 'projectName.give.appName.view3'),
url(r'^contact/thanks/$', 'projectName.appName.views.view4'),
)
Current configuration of urls.py on separate project:
However, I seem to be facing inconsistent results with this other configuration on another project.
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^foo/$', 'projectName.appName.views.view1'),
url(r'^foo/bar1/', 'projectName.appName.views.view2'),
url(r'^foo/bar2/', 'projectName.appName.views.view3'),
)
What's wrong:
For example, when I visit the URL at /foo/bar1, it inconsitently either brings me to the desired URL or loads up /foo/ instead while still having /foo/bar1 displayed in the URL bar in the browser.
/foo/bar2/ mostly (19 out of 20 times) returns a 404 when that URL is requested. Otherwise it shows /foo/ but the original URL remains in the browser. It just seems so weird and odd, and this has never happened to me in Django before.
If you noticed the missing $'s, I found out through experimentation that this configuration is slightly more reliable. With the $'s, all my URLs end up loading /foo/ while still showing the requested URL in the browser.
I guess that it's worthy to note that /foo/ and /foo/bar1/ were mostly working fine (but calling /foo/bar1/ in the browser would still load up /foo/ instead perhaps 1 out of every 20 times called or so) until I added /foo/bar2/.
How now brown cow:
I guess this would have to do with regexes, but I'm not sure how should I be handling regexes to make this work, other than to follow what I've done before that was right but now can't work. Yeah so I don't know how does regex work.
If someone could point me in the right direction or tell me where might I have gone wrong that would be very helpful. Thank you!
Other info:
I'm developing on Python 2.7, Django 1.3.7 on PythonAnywhere, not locally.
Hi thanks for looking into this.
I have been following Django's tutorial on URLs and got a bit confused/stuck on this part:
https://docs.djangoproject.com/en/1.4/intro/tutorial03/#decoupling-the-urlconfs
what I do not understand is if, say, on page mypage.com I provide only 2 possible URLs for mypage.com/polls and mypage.com/admin, what happens if the user goes to mypage.com? Obviously, I thought, the user will need to see some sort of 'welcome' page so I decided to add another URL to that urls.py:
urlpatterns = patterns('',
url(r'^/', 'myapp.views.welcome'), #when it's just mysite.com
url(r'^myapp/', include('myapp.urls')), #includes everything with mysite.com/myapp/...
url(r'^admin/', include(admin.site.urls)),
)
But then I get redirected to that welcome view from whichever page, whether i go to /myapp or not. So, I decided to create a views.py file outside myapps folder and put that welcome page there, and it seems to have worked, apart from that I get a 404.
I am so confused! Could you explain in lamers' terms please
Thanks,
blargie-bla
It should be
url(r'^$', 'myapp.views.welcome')
otherwise any URL will match the pattern. Django will call the view for the first pattern in urlpatterns that matches, so you need to be specific and include the end-of-the-line character ($) into the pattern.
I'm working with Django, admittedly for the first time doing anything real.
The URL config looks like the following:
urlpatterns = patterns('my_site.core_prototype.views',
(r'^newpost/$', 'newPost'),
(r'^$', 'NewPostAndDisplayList'), # capture nothing...
#more here... - perhaps the perma-links?
)
This is in an app's url.py which is loaded from the project's url.py via:
urlpatterns = patterns('',
# only app for now.
(r'^$', include('my_site.core_prototype.urls')),
)
The problem is, when I receive a 404 attempting to utilize newpost, the error page only shows the ^$ -- it seems to ignore the newpost pattern...
I'm sure the solution is probably stupid-simple but right now I'm missing it. Can someone help get me on the right track...
Your pattern for the include will only match an empty URL string, change it to a prefix which should be mapped to the included urls, or remove the $ from that pattern.
I am trying to refactor out my application a little bit to keep it from getting too unwieldily. So I started to move some of the urlpatterns out to sub files as the documentation proposes.
Besides that fact that it just doesn't seem to be working (the items are not being rerouted) but when I go to the admin, it says that 'urlpatterns has not been defined'.
The urls.py I have at the root of my application is:
if settings.ENABLE_SSL:
urlpatterns = patterns('',
(r'^checkout/orderform/onepage/(\w*)/$','checkout.views.one_page_orderform',{'SSL':True},'commerce.checkout.views.single_product_orderform'),
)
else:
urlpatterns = patterns('',
(r'^checkout/orderform/onepage/(\w*)/$','commerce.checkout.views.single_product_orderform'),
)
urlpatterns+= patterns('',
(r'^$', 'alchemysites.views.route_to_home'),
(r'^%s/' % settings.DAJAXICE_MEDIA_PREFIX, include('dajaxice.urls')),
(r'^/checkout/', include('commerce.urls')),
(r'^/offers',include('commerce.urls')),
(r'^/order/',include('commerce.urls')),
(r'^admin/', include(admin.site.urls)),
(r'^accounts/login/$', login),
(r'^accounts/logout/$', logout),
(r'^(?P<path>.*)/$','alchemysites.views.get_path'),
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root':settings.MEDIA_ROOT}),
The urls I have moved out so far are the checkout/offers/order which are all subapps of 'commerce' where the urls.py for the apps are so to be clear.
/urls.py in questions (included here)
/commerce/urls.py where the urls.py I want to include is:
order_info = {
'queryset': Order.objects.all(),
}
urlpatterns+= patterns('',
(r'^offers/$','offers.views.start_offers'),
(r'^offers/([a-zA-Z0-9-]*)/order/(\d*)/add/([a-zA-Z0-9-]*)/(\w*)/next/([a-zA-Z0-9-)/$','offers.views.show_offer'),
(r'^reports/orders/$', list_detail.object_list,order_info),
)
and the applications offers lies under commerce.
And so the additional problem is that admin will not work at all, so I'm thinking because I killed it somewhere with my includes.
Things I have checked for:
Is the urlpatterns variable accidentally getting reset somewhere (i.e. urlpatterns = patterns, instead of urlpatterns+= patterns)
Are the patterns in commerce.urls valid (yes, when moved back to root they work).
So from there I am stumped. I can move everything back into the root, but was trying to get a little decoupled, not just for theoretical reason but for some short terms ones.
Lastly if I enter www.domainname/checkout/orderform/onepage/xxxjsd I get the correct page. However, entering www.domainname/checkout/ gets handled by the alchemysites.views.get_path.
If not the answer (because this is pretty darn specific), then is there a good way for troubleshoot urls.py? It seems to just be trial and error. Seems there should be some sort of parser that will tell you what your urlpatterns will do.
Adding the following line in my urls.py worked for me:
from django.conf.urls import include
Have a look at the django docs for including other url confs. I think you might have misunderstood them. In particular
Whenever Django encounters include(), it chops off whatever part of the URL matched up to that point and sends the remaining string to the included URLconf for further processing.
As an example, you have
(r'^/checkout/', include('commerce.urls')),
(r'^/offers',include('commerce.urls')),
(r'^/order/',include('commerce.urls')),
This means that
/checkout/offers/
/offers/offers/
/order/offers/
will all match the url pattern (r'^offers/$','offers.views.start_offers') in commerce/urls.py.
If you want to define a view for /checkout/ in commerce.py, you need to add the pattern
(r'^$', 'path_to_your_view')
because the /checkout/ part will be chopped off by the include()
As, an aside:
In /commerce/urls.py, use
urlpatterns = patterns('',
...
for the first patterns you define. You can then use urlpatterns += later in the same file.