I am new to python and django and I am working on a project which is already build and I am just learning to understand it by adding some new views.
Application uses TemplateViews and I created a view which is just like the other views created. The Url pattern is also kind of same to the urls which are working fine. But my new page I created is not working and is giving me the error.
Working urls:
urls.py:
**
url(r'^aboutxyz/$', TemplateView.as_view(template_name="aboutxyz.html"), name='about_xyz'),
url(r'^contactus/$', TemplateView.as_view(template_name="contactus.html"), name='contact_us'),
**
base.html:
**
<li>About XYZ</li>
<li>Contact Us</li>
**
These 2 pages are working fine. But when I add this:
urls.py:
url(r'^aboutxyzsg/$', TemplateView.as_view(template_name="aboutxyzsg.html"), name='about_xyz_sg'),
base.html:
"<li>About XYZ sg</li>"
Here is the code from urls.py file which contains url_patterns:
urlpatterns = patterns('',
url(r'^grappelli/', include('grappelli.urls')), # grappelli URLS
url(r'^admin/', include(admin.site.urls)),
)
urlpatterns += i18n_patterns(
'',
# zinnia-tinymce
url(r'^tinymce/', include('tinymce.urls')),
url(r'^tinymce/zinnia/', include('zinnia_tinymce.urls')),
# index (home)
url(r'^$', Index.as_view(), name="main_page"),
# all-auth account
url(r'^accounts/', include('allauth.urls')),
# custom user
url(r'^accounts/', include('users.urls')),
# Privacy Policy
url(r'^privacypolicy/$', TemplateView.as_view(template_name="privacypolicy.html"), name='privacy_policy'),
# About XYZ
url(r'^contactus/$', TemplateView.as_view(template_name="contactus.html"), name='contact_us'),
url(r'^aboutxyz/$', TemplateView.as_view(template_name="aboutxyz.html"), name='about_xyz'),
url(r'^aboutxyzsg/$', TemplateView.as_view(template_name="aboutxyzsg.html"), name='about_xyz_sg'),
)
It is not working and giving me error:
My error log shows:
"NoReverseMatch: Reverse for 'about_xyz_sg' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []"
Please help me I am in deep trouble
P.S. - I tried putting aboutxyzsg url pattern before aboutxyz and still same error
Related
I'm trying to make a website using Django and I got some error message like this
Request URL: http://127.0.0.1:8000/store.html
Using the URLconf defined in greatkart.urls, Django tried these URL patterns, in this order:
admin/
[name='home']
store/
^media/(?P<path>.*)$
The current path, store.html, didn't match any of these.
The problem is when I tried to click button it always print ./store.html not the ./store
it's my html code for the button
See all
And this is my Django for urls.py (main)
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home, name='home'),
path('store/', include("store.urls"))
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
This urls.py(store)
urlpatterns = [
path('', views.store, name='store'),
path('<slug:category_slug>/', views.store, name='product_by_category'),
]
views.py
def store(request, category_slug = None):
return render(request, 'store/store.html', context)
Anyone have some idea? I want to fix it without changing the HTML code because I've tried it and when I click on the buttons twice that make some error because the URL print the ./store twice
Here the url should be absolute(starting with a / excluding you localhost address) and should not include .html.
So Your Url should be :
/store
and the anchor tag should be :
See all
I am new to Django and I am trying to create sample project in it. Please help me in resolving this error.
My Main URLs.py file
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^t20_predict/', include('PredictMatch.urls')),
]
My Apps URLs.py file
app_name = 'PredictMatch'
urlpatterns = [
# t20_predict/T20
url(r'^T20/$', views.t20index, name='t20index'),
]
becuase
url(r'^T20/$', views.t20index, name='t20index')
you are not expecting any id ,the url is just t20_predict/T20/ -> see here there is no id
if you want the url to receive id as well the url pattern should be
url(r'^T20/(?P<id>[0-9]+)/$', views.t20index, name='t20index')
I have been working with i18n so that the URL included the prefix "/en/" or "/es/" depending on the users preferred language.
So far it was working fine while using Django 1.9 it even placed automatically the prefix even when the user didn't submit it in the URL (i.e. mySite.com would redirect to mySite.com/en/).
Now that I upgraded to 2.0 it is not working and it shows a 404 error:
Using the URLconf defined in smce.urls, Django tried these URL patterns, in this order:
en/
^static/(?P.*)$
^images/(?P.*)$
The empty path didn't match any of these.
At my root urls.py i have:
urlpatterns = i18n_patterns(
path('admin/', admin.site.urls),
path('login/', anonymous_required(views.login), {'template_name': 'login.html', 'authentication_form': LoginForm}, name='login'),
path('', include('matrix.urls'), name='matrix'),
)
Any help or guidance would be appreciated.
For solving this problem just set these configs in settings.py
LANGUAGE_CODE='en'
prefix_default_language=False
im trying to get my url named, so it can be reversed in my django app.
mysite/urls.py:
urlpatterns = patterns('',
# Examples:
url(r'^$', 'myapp.views.redirect_to_home'),
url(r'^admin/', include(admin.site.urls)),
url(r'^myapp/', include('myapp.urls')),)
myapp/urls.py
urlpatterns = patterns('',
url(r'(?i)^$', views.redirect_to_home),
url(r'(?i)^Login/$', views.home, name="home"),
url(r'(?i)^Logout/$', views.logout_user, name="logout_user"),)
be minded that i had purpusly added the '(?i)^' in the beggining of every regex, to make the urls in-case sensitive.
but, having this string '(?i)^' had made my reverse function to fail saying
Reverse for 'home' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: ['myapp/(?i)^Login/$']
after trying to remove the (?i)^ , i noticed the reverse succeeds.
What can i do to make my urls in-case sensitive, and still reversable?
Thanks.
I started going through tut but then got stuck on the page.
tutorial page 3 - django
I exactly followed the tut to the point where it asks to goto localhost:8000/polls/.
There starts the problem, it is not working, states an error
Please, tell how to correct the error.
That page is a 404 page not found. This suggests to me that you have either not configured your URL's correctly or it's missing.
/project/urls.py
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls')),
)
Where polls.urls points to your app URL at /polls/urls.py
So now in your polls/url.py add the index as described.
from django.conf.urls import patterns, url
from polls import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index')
)
https://docs.djangoproject.com/en/1.6/intro/tutorial03/#write-your-first-view