Using Django 1.3 with development server
I try to connect with: http://127.0.0.1:8000/lang/en
The answer is:
Using the URLconf defined in
pruebas.urls, Django tried these URL
patterns, in this order:
^admin/
^correo/$
^login/$
^lang/(?P\w+)/$
^site_static/(?P.*)$
The current URL, , didn't match any of
these.
And this is my "urls.py":
from pruebas import settings
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'pruebas.views.home', name='home'),
# url(r'^pruebas/', include('pruebas.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)),
(r'^correo/$', 'mailclient.views.index'),
(r'^login/$', 'kusers.views.klogin'),
# Language change
(r'^lang/(?P<lang_code>\w+)/$', 'kusers.views.lang'),
)
if settings.DEBUG:
urlpatterns += patterns('',
(r'^site_static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_ROOT}),)
I think that the line:
(r'^lang/(?P\w+)/$', 'kusers.views.lang'),
would match with "http://127.0.0.1:8000/lang/en" but it seems that I'm wrong.
Thanks in advance
The code in kusers/views.py is:
def lang(request, lang_code):
request.session['django_language'] = lang_code
return HttpResponseRedirect( "/" )
SOLVED.
The problem wasn´t urls.py config. The problem was the 'kuser' app folder estructure.
Thanks
If you put a trailing slash on the url it will work, as in:
http://127.0.0.1:8000/lang/en/
Related
Main url file:
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
url(r'^$', include('myapp.urls')),
url(r'^admin/', include(admin.site.urls)),
)
My app url file:
from django.conf.urls import patterns, url
from mainapp import views
urlpatterns = patterns('',
url(r'^$', views.index),
url(r'^url1$', views.url1),
url(r'^url2$', views.url2)
)
When I go to "/", it shows the views.index from my app fine. However, it says "Page not found (404)" for url1 and url2.
Using the URLconf defined in myproject.urls, Django tried these URL patterns, in this order:
^$
^admin/
The current URL, url1, didn't match any of these.
What's up with that?
You are matching '^$', which is an empty string, so your other urls are not called.
Try:
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('myapp.urls'))
)
Note that I changed the ordering. This is so that myapp will never override other, more specific urls like admin.
r'^url1$'
^ means start here;
$ means end here.
so, it is an empty string. it does not make sense to put anything between like you did ^ ... $.
how about to try: r'^$', 'views.url1'),
?
I am getting the following error when ever I access the url's except /home.
Page not found (404)
Request Method: GET Request URL
Using the URLconf defined
in report_ui.urls, Django tried these URL patterns, in this order:
^admin/
^home/
The current URL, individual/, 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.
The code :
urls.py
# -*- coding: utf-8 -*-
from django.conf.urls import patterns, url
urlpatterns = patterns('dnslog.views',
# Examples:
url(r'$', 'home'),
url(r'^report/$', 'report'),
url(r'^angular/$', 'angular'),
url(r'^linear/$', 'LinearPrediction'),
url(r'^splunk/$', 'splunkdata'),
url(r'^toyprediction/$', 'toyprediction'),
url(r'^saleprediction/$', 'GetSalesPrediction'),
url(r'^customerprediction/$', 'GetCustomerPrediction'),
url(r'^monthwiseprediction/$', 'GetMonthWiseSalesPrediction'),
url(r'^getlinearprediction/(?P<duration>.\w+)/$', 'GetLinearPrediction'),
url(r'^getprediction/$', 'GetPredictionReport'),
url(r'^modeldata/(?P<obj>.\w+)/$', 'GetConsolidatedObjectData'),
# url(r'^modeldata/(?P<date>\d{4}-\d{2}-\d{2})/$', 'GetConsolidatedObjectData'),
url(r'^home/(?P<date>\d{4}-\d{2}-\d{2})/$', 'GetConsolidateHits'),
url(r'^bytes/$', 'BytesDownload'),
url(r'^BytesDownload/(?P<date>\d{4}-\d{2}-\d{2})/$',
'GetConsolidateDownloadBytes'),
url(r'^getCntPerData/$', 'GetConsolidateCntPer'),
url(r'^help/$', 'help'),
url(r'^individualhits/$', 'individualhits'),
url(r'^individualhits1/(?P<empid>.+)/(?P<date>\d{4}-\d{2}-\d{2})/$',
'GetIndividualHits'),
url(r'^bubble/$', 'bubble'),
url(r'^bubblechart/(?P<date>\d{4}-\d{2}-\d{2})/$',
'GetConsolidateHitsForBubble'),
#url(r'^test/$', 'test'),
url(r'^domaincloud/$', 'cloud'),
url(r'^getdomaincloud/(?P<date>\d{4}-\d{2}-\d{2})/$', 'Getclouddata'),
url(r'^circleview/$', 'circle'),
url(r'^getcircleview/(?P<date>\d{4}-\d{2}-\d{2})/$', 'Getcircledata'),
url(r'^comparisionview/$', 'comparision'),
url(r'^getcomparision/(?P<date>\d{4}-\d{2}-\d{2})/$', 'Getcomparisiondata'),
url(r'^individualcomparision/(?P<domain>.+)/(?P<empid>.+)/(?P<date>\d{4}-\d{2}-\d{2})/$',
'GetIndividualComparisonData'),
url(r'^trendview/$', 'trend'),
url(r'^gettrendview/$', 'Gettrenddata'),
url(r'^zoomabletree/$', 'zoomabletree'),
url(r'^getzoomabletree/(?P<date>\d{4}-\d{2}-\d{2})/$', 'Getcircledata'),
##url(r'^report_ui/', include('report_ui.foo.urls')),
#url(r'^individualConsolidatedHits/$', 'individualConsolidatedHits'),
url(r'^getConsolidatedCategoryDetails/(?P<date>\d{4}-\d{2}-\d{2})/$',
'getConsolidatedCategoryDetails'),
# overall individual reports
url(r'^individual/$', 'individual'),
## individual Category report
#url(r'^individualcategory/$', 'individualcategory'),
url(r'^GetIndividualCategory/(?P<empid>.+)/(?P<date>\d{4}-\d{2}-\d{2})/$',
'GetIndividualCategory'),
url(r'^twitter/$','twitter'),
root urls.py
from django.conf.urls import patterns, include, url
# to include the media url
from django.conf import settings
from django.conf.urls.static import static
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'report_ui.views.home', name='home'),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
url(r'^home/', include('dnslog.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
)
Any help would be appreciated. Thanks!
Either change your root urls.py
url(r'^home/', include('dnslog.urls')),
to:
url(r'^/', include('dnslog.urls')),
Or change your request from
from:
individual/
to:
/home/individual
Hello and thank you in advance,
When I installed django-profiles and django-registration. I believe I followed a tutorial correctly on how to configure them:
http://agiliq.com/books/djenofdjango/chapter5.html#reusable-apps
Now when I try to access website.com/accounts I get a 404 page:
Using the URLconf defined in acme_p.urls, Django tried these URL patterns, in this order:
^$
^accounts/
^admin/doc/
^admin/
The current URL, accounts, didn't match any of these.
My urls files look like this:
#acme_p urls - Django Project
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', include('user_prof.urls')),
# Examples:
# url(r'^$', 'acme_p.views.home', name='home'),
# url(r'^acme_p/', include('acme_p.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)),
)
user_prof urls.py - Django App one level below project mentioned above
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^login/$', 'auth.views.login_user'),
(r'^accounts/', include('registration.urls')),
# (r'^accounts/', include('registration.backends.default.urls')),
)
Thank you for you help.
dp
(r'^accounts/', include('registration.urls')), should be in the root urls.py not the app urls.py
There is no website.com/account in the configuration, there is only website.com/account/(more) where (more) has the rest of the url that is given to the django-registration module. You could try website.com/account/login/ for example to check if the django-registration module is working.
Also you should just put those on the root urls.py file.
I've created a blog using django and hosted it on dotcloud http://www.honeybunny.dotcloud.com/blog/ its working fine on the localhost but when i try to access it online an extra slash is added to the urls what could be the reason ?
www.sitename.com/admin/
becomes
www.sitename.com//admin/
my urls.py is as following
from django.conf.urls.defaults import patterns, include, url
from django.views.generic.simple import redirect_to
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
import blog
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$',redirect_to,{'url':'/blog'}),
url(r'^admin/', include(admin.site.urls)),
url(r'^blog/',include('blog.urls')),
)
Also submitting the login form on the admin redirects me to http://admin/ while in the local environment it works perfectly fine .
UPDATE : My problem seems remarkably similar to the one described here .
From django tutorials the url file should look like the one below.
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^articles/2003/$', 'news.views.special_case_2003'),
(r'^articles/(\d{4})/$', 'news.views.year_archive'),
(r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'),
(r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'),
)
from django.conf.urls.defaults import patterns, include, url
from django.views.generic.simple import redirect_to
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'honeybunny.views.home', name='home'),
# url(r'^honeybunny/', include('honeybunny.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'^$',redirect_to,{'url':'/blog'}),
url(r'^admin/$', include(admin.site.urls)),
)
Is my urls.py file
I have deleted import blog line because I don't have blog module.
It seemed to be a problem with dotcloud the same code worked without any errors when i uploaded it to epio
In my urls file I have configured the Django admin application to run off the url /adminDJ/. However it doesn't run. It loads up my own admin stuff. Here is my urls.py:
(r'^admin/add/member/$', 'astonomyStuff.attendance.views.newMember'),
(r'^admin/add/$', 'astonomyStuff.attendance.views.addPage'),
(r'^admin/$', 'astonomyStuff.attendance.views.adminPage'),
(r'^adminDJ/$', include(admin.site.urls)),
(r'^talks/$', 'astonomyStuff.attendance.views.talksIndex'),
(r'^talks/past/$', 'astonomyStuff.attendance.views.viewAllTalks'),
(r'^members/$', 'astonomyStuff.attendance.views.viewMembers'),
(r'^members/(?P<member_number>[^/]+)/$', 'astonomyStuff.attendance.views.viewMember'),
(r'^members/(?P<member_number>[^/]+)/delete$', 'astonomyStuff.attendance.views.deleteMember'),
(r'^admin/add/talk/$', 'astonomyStuff.attendance.views.newTalk'),
(r'^talks/(?P<talk_title>[^/]+)/$', 'astonomyStuff.attendance.views.viewTalk'),
(r'^attendance/(?P<talk_title>[^/]+)/$', 'astonomyStuff.attendance.views.viewAttendance'),
(r'^databrowse/(.*)', databrowse.site.root),
(r'^adminDoc/doc/', include('django.contrib.admindocs.urls')),
(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}),
(r'^accounts/profile/$', 'astonomyStuff.attendance.views.adminPage'),
(r'^admin/add/attendance/$', 'astonomyStuff.attendance.views.addAttendance'),
(r'^members/(?P<member_number>[^/]+)/edit$', 'astonomyStuff.attendance.views.editMember'),
(r'^public/talks/$', 'astonomyStuff.attendance.views.publicViewTalks')
I have rearranged the order to see if this was the problem but that's not fixed it. Must the django admin application run on /admin/?
Edit
I have had the admin application working before just to let you know it only broke when I played around with the urls.
Edit 2
Here is my complete urls.py:
from django.conf.urls.defaults import *
from astonomyStuff.attendance.models import Member
from astonomyStuff.attendance.models import Non_Member
from astonomyStuff.attendance.models import Talk
from astonomyStuff.attendance.models import Event_Attendance
from django.contrib import admin
from django.contrib import databrowse
admin.autodiscover()
admin.site.register(Member)
admin.site.register(Non_Member)
admin.site.register(Talk)
admin.site.register(Event_Attendance)
databrowse.site.register(Member)
databrowse.site.register(Non_Member)
databrowse.site.register(Talk)
databrowse.site.register(Event_Attendance)
urlpatterns = patterns('',
# Example:
# (r'^astonomyStuff/', include('astonomyStuff.foo.urls')),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
# (r'^admin/add/member/$', 'astonomyStuff.attendance.views.newMember'),
# (r'^admin/add/$', 'astonomyStuff.attendance.views.addPage'),
# (r'^admin/$', 'astonomyStuff.attendance.views.adminPage'),
(r'^admin/$', include(admin.site.urls)),
(r'^talks/$', 'astonomyStuff.attendance.views.talksIndex'),
(r'^talks/past/$', 'astonomyStuff.attendance.views.viewAllTalks'),
(r'^members/$', 'astonomyStuff.attendance.views.viewMembers'),
(r'^members/(?P<member_number>[^/]+)/$', 'astonomyStuff.attendance.views.viewMember'),
(r'^members/(?P<member_number>[^/]+)/delete$', 'astonomyStuff.attendance.views.deleteMember'),
# (r'^admin/add/talk/$', 'astonomyStuff.attendance.views.newTalk'),
(r'^talks/(?P<talk_title>[^/]+)/$', 'astonomyStuff.attendance.views.viewTalk'),
(r'^attendance/(?P<talk_title>[^/]+)/$', 'astonomyStuff.attendance.views.viewAttendance'),
(r'^databrowse/(.*)', databrowse.site.root),
(r'^adminDoc/doc/', include('django.contrib.admindocs.urls')),
(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}),
(r'^accounts/profile/$', 'astonomyStuff.attendance.views.adminPage'),
# (r'^admin/add/attendance/$', 'astonomyStuff.attendance.views.addAttendance'),
(r'^members/(?P<member_number>[^/]+)/edit$', 'astonomyStuff.attendance.views.editMember'),
(r'^public/talks/$', 'astonomyStuff.attendance.views.publicViewTalks'),
)
Not this (r'^adminDJ/$', include(admin.site.urls)),
But this (r'^adminDJ/', include(admin.site.urls)), ##note, no $ in the regex
Remember folks, gotta check your regexes...
This is probably nothing but it caught my eye. From the first snippet:
(r'^admin/$', 'astonomyStuff.attendance.views.adminPage'),
(r'^adminDJ/$', include(admin.site.urls)),
And the second snippet:
(r'^admin/$', include(admin.site.urls)),
Is this how you want it? The first snippet uses ^adminDJ/$ while the second one uses admin/$ opposite include(admin.site.urls).
Are these two files? And are the both used? In that case the first snippet could very well override the second, thereby causing your admin views to show up instead of Django's.