Today when I code my blog with 'Building_a_blog_in_30_mins_with_Django_Screencast',I meet some problems.When I click the title with the article,it can't appear the right page.!
Page not found (404)
Request Method: GET
Using the URLconf defined in myblog.urls, Django tried these URL patterns, in this order:
^$
^(?P<pk>\d+)/$
^admin/
^admin/doc/
The current URL, app/1, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
and it's my urls.py:
url(r'^$',ListView.as_view(queryset=Post.objects.all().order_by("created[:2]template_name=" blog.html")),
url(r'^(?P<pk>\d+)/$',DetailView.as_view( model=Post, template_name="post.html")),
url(r'^admin/', include(admin.site.urls)),
url(r'^admin/doc/', include('django.contrib.admindocs.urls'))
I doesn't konw what is going on with it.Please help,thanks!
You need to add 'app/' in your url.
url(r'^app/(?P<pk>\d+)/$',DetailView.as_view( model=Post, template_name="post.html")),
Or may be you need to define these urls in urls.py of your app (named app ?) and include it in sites main urls.py
url(r'app/', include('app.urls'))
Related
I am trying to call a function in my views.py by pasting a url http://127.0.0.1:8000/upload_results/UniEX_HG1_A15 in the web browser,
but the request fails and I can not see why my URL pattern does not work.
The error:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/upload_results/UniEX_HG1_A15
Using the URLconf defined in varview.urls, Django tried these URL patterns, in this order:
^$ [name='show_index']
^admin/
^upload/ [name='varview_submission']
^upload_results/(?P<project_id>[0-9A-Za-z_]+)/ [name='varview_upload_results']
^validate/(?P<project_id>[0-9A-Za-z_]+)/ [name='varview_validate']
^filterallprojects/[0-9A-Za-z_]+ [name='varview_filterallprojects']
^project/(?P<project_id>[0-9A-Za-z_]+)/wgsmetrics/ [name='varview_wgsmetrics']
^project/(?P<project_id>[0-9A-Za-z_]+)/targetgenecoverage/ [name='varview_targetgenecoverage']
^project/(?P<project_id>[0-9A-Za-z_]+)/(?P<display_option>[0-9A-Za-z_]+)/ [name='varview_project']
^media\/(?P<path>.*)$
The current path, upload_results/UniEX_HG1_A15, didn't match any of these.
And here is my urls.py:
from django.conf import settings
from django.conf.urls import url
from django.conf.urls.static import static
from django.contrib import admin
from varview import views
from varview.forms import DataUploaderForm1, DataUploaderForm2, GetProjectIdForm
urlpatterns = [
url(r'^$', views.show_index, name='show_index'),
url(r'^admin/', admin.site.urls),
url(r'^upload/', views.init_submission, name='varview_submission'),
url(r'^upload_results/(?P<project_id>[0-9A-Za-z_]+)/', views.upload_results, name='varview_upload_results'),
]
This already worked some time ago, but in the meantime I did many changes.
Latest change was to include celery (djcelery).
The index page and others still work. I already read many posts related to django-url, but could not figure it out.
Thank you for your help.
Note your URL has a trailing slash,
^upload_results/(?P<project_id>[0-9A-Za-z_]+)/
but you are trying to access a URL without the trailing slash
/upload_results/UniEX_HG1_A15
Normally, Django will redirect to the URL with the trailing slash. Perhaps your MIDDLEWARE setting is incorrect, or you have set APPEND_SLASH to False.
I'm brand new to Django and Python. I've only done php.
It took me three tries, but I've almost Django installed correctly. I followed the tutorial on installing it, and it worked. So I enabled the admin, panel, and set up mysql.
The admin panel works, and I've got my static folder so it has all of the css as well. But when I go to the main page I get this 404. (My project is called firstweb) So whenI go into firstweb there is a 404, but firstweb/admin works.
Using the URLconf defined in firstweb.urls, Django tried these URL patterns, in this order:
1. ^admin/
The current URL, firstweb/, didn't match any of these.
And I'm confused by the whole runserver thing. Is that some other little server other than my Apache? Why do I need to start it every time?
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'firstweb.views.home', name='home'),
# url(r'^firstweb/', include('firstweb.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
It looks like your url conf does not include any url pattern for any other pages accept the admin.
If you want the root url to display a page, uncomment this line
url(r'^$', 'firstweb.views.home', name='home'),
And then make sure that in firstweb/views.py you have a view function called 'home', which I assume is part of the tutorial.
I have Django 1.5.1 installed and django-cms 2.4.2
However I have not integrated zinnia blog and django-cms just yet.
I was able to create a blog entry but when going to the blog entry
8000/en/weblog/2013/10/13/test-entry/
I receive a 404 Page not Found
any thoughts?
Possible cause: order of urlpatterns inclusions in urls.py. Django-Cms design lack.
Fix: put cms.urls after zinnia.urls:
# patterns or i18n_patterns here.
urlpatterns = i18n_patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^blog/', include('zinnia.urls')),
url(r'^comments/', include('django.contrib.comments.urls')),
url(r'^', include('cms.urls')),
)
Explanation:
If you include cms urls before zinnia urls, django-cms "slug" pattern matches a wide range of URLs including Zinnia blog entry URL:
<RegexURLPattern pages-details-by-slug ^(?P<slug>[0-9A-Za-z-_.//]+)/$>
As an example, it will match: "blog/2014/01/20/test-article-about-something/"
After it matched as django-cms:pages-details-by-slug, the whole URI is stored in the "slug" variable and is provided as an argument (in "kwargs") to cms.views.detail view function. And this view will call:
cms.utils.page_resolver import get_page_from_request(request, use_path=slug)
and cms will not find (and will raise "Resolver404" exception) any suitable page to render because this URI belongs to Zinnia blog.
End of story.
Resources:
"details" view can be found here: cms.views
django url resolving logic is here: django.core.urlresolvers mainly in two "resolve" methods. (lines: 315 *recursive, 209 *non-recursive)
Hello I'm a newbie in Django.
I'm creating a blog app for practice and I wanted to separate the urls that relates to the blog application from the urls that relates to the other applications.
Since there are many blog-related url patterns, I just included in the main urls.py.
Here is my urls.py:
My_Project/My_Project/urls.py
urlpatterns = patterns('',
# Blog
url(r'^$', include('app_blog.urls'), name='app_blog'),
# Admin
url(r'^admin/$', include(admin.site.urls), name='admin_page'),
......
My_Project/app_blog/urls.py
urlpatterns = patterns('',
# Index page
url(r'^index/$', index_page),
# User page
url(r'^user/(?P<pk>\d+)/', UserDetail.as_view(), name='user_detail'),
......
So I expected that when I navigate to "www.example.com/index" the browser would show the index_page view and for "www.example.com/user/1", it will show the user detail view for user with id equal to 1.
For some reason, however, it shows the 404 page not found error for both pages.
Where have I gone wrong?
name parameter is for a single url pattern. Remove it from this line in My_Project/My_Project/urls.py
The regex pattern should not be '^$'. Instead just plain ''.
url(r'', include('app_blog.urls'))
The problem is here:
# Blog
url(r'^$', include('app_blog.urls'), name='app_blog'),
~~~
You are restricting your url to an empty path, that means everything that is not an empty path will not be matched against app_blog.urls.
Do this instead:
# Blog
url(r'^', include('app_blog.urls')),
I have a django app that is mostly done, and the URLs work perfectly when I run it with the manage.py runserver command. However, I've recently tried to get it running via lighttpd, and many links have stopped working.
For example: http://mysite.com/races/32 should work, but instead throws this error message.
Page not found (404)
Request Method: GET
Request URL: http://mysite.com/races/32
Using the URLconf defined in racetrack.urls, Django tried these URL patterns, in this order:
^admin/
^create/$
^races/$
^races/(?P<race_id>\d+)/$
^races/(?P<race_id>\d+)/manage/$
^races/(?P<text>\w+)/$
^user/(?P<kol_id>\d+)/$
^$
^login/$
^logout/$
The current URL, 32, didn't match any of these.
The request URL is accurate, but the last line (which displays the current URL) is giving 32 instead of races/32 as expected.
Here is my urlconf:
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('racetrack.races.views',
(r'^admin/', include(admin.site.urls)),
(r'^create/$', 'create'),
(r'^races/$', 'index'),
(r'^races/(?P<race_id>\d+)/$', 'detail'),
(r'^races/(?P<race_id>\d+)/manage/$', 'manage'),
(r'^races/(?P<text>\w+)/$', 'index'),
(r'^user/(?P<kol_id>\d+)/$', 'user'),
# temporary for index page replace with welcome page
(r'^$', 'index'),
)
urlpatterns += patterns('django.contrib.auth.views',
(r'^login/$', 'login', {'template_name': 'races/login.html'}),
(r'^logout/$', 'logout', {'next_page': '/'}),
)
Thank you.
I would think that the problem lies in the configuration of lighttpd.
Django is capable of "translating" "request urls" to "current urls" for the url checking, for example via the django.root configuration for mod_python.