So I'm attempting to Django, and I've gotten a few urls working but one set just wont work.
It keeps asking for a argument but it shouldn't require one.
Error below.
NoReverseMatch at /
Reverse for 'about' with no arguments not found. 1 pattern(s) tried: ['$about/']
Error during template rendering
In template hub\templates\partials\footer.html, error at line 33
hub\templates\partials\footer.html line 33
About
hub/urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.HomePageView.as_view(), name='index'),
url(r'^about/', views.AboutPageView.as_view(), name='about'),
url(r'^contact/', views.ContactPageView.as_view(), name='contact'),
]
storyarchive/urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^$', include('hub.urls', namespace='hub')),
url(r'^community/', include('community.urls', namespace='community')),
url(r'^forum/', include('forum.urls', namespace='forum')),
url(r'^story/', include('story.urls', namespace='story')),
url(r'^admin/', admin.site.urls),
]
It worked before I started to use the {% url %} builtin.
Django Version: 1.11.5
Python Version: 3.4.4
You need to remove the $ from your urlpattern which includes hub.urls. That only matches with an empty string. So it won't get matched with about.
Thats why it shows $about/ in your error log too. Change your storyarchive/urls.py like this:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^', include('hub.urls', namespace='hub')),
url(r'^community/', include('community.urls', namespace='community')),
url(r'^forum/', include('forum.urls', namespace='forum')),
url(r'^story/', include('story.urls', namespace='story')),
url(r'^admin/', admin.site.urls),
]
Related
I don't know why this problem happened.enter image description here
These errors occur when you read a book and follow it. I don't know what to do. Give me a hand.
Source Code
This is my fistsite.py source code.
fistsite.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
enter code here
path('admin/', admin.site.urls),
path('polls/', include('polls.urls')),
]
After changing the source code above
now fistsite.py
from django.contrib import admin
from django.urls import path, include
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('/polls', views.polls, name='polls'),
path('/admin', views.admin, name='admin')
]
But there was an error.enter image description here
my projcetenter image description here
Assuming that you have Django version > 2.0, you should add to your urls.py file something like this:
from django.contrib import admin
from django.urls import path, include
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('/polls', views.polls, name='polls'),
path('/admin', views.admin, name='admin')
]
So as shown in the error page, your Django project tried to go to localhost:8000/admin/ and localhost:8000/polls/ but the site you are trying to access in localhost:8000/ . You haven't defined any url pattern for capturing this scenario. What you can do is in your urls.py, add this line under urlpatterns :
urlpatterns=[
path('', views.index, name='index'),
...............
]
This works if you are using Django version>2.0
If you are using Django version<2.0 then you can add this:
urlpatterns=[
url(r'^$', views.index, name='index'),
...............
]
If you want to access you "polls". After change your fistsite.pytry this
url = "localhost:8000/polls/
and you are giving only localhost:8000 if did not create any app then this url will work.
I am having a trouble mapping urls correctly. I've included my code below.
I am able to run the code just fine, but when I click the "about" hyperlink, I get an error saying
The current URL, rango/about/, didn't match any of these.
When I put in the URL just "rango/", removing the "about", I get the following error:
The current URL, rango/, didn't match any of these.
I am a complete beginner with Django and have been going through the Tango with Django book, but currently stuck with the exercises on Ch3.
Any help is much appreciated. Thank you!
tango_with_django_project.urls.py
from django.conf.urls import url
from django.contrib import admin
from django.conf.urls import include
from rango import views, urls
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^rango/',include('rango.urls')),
# above maps any URLs starting with rango/ to
# be handled by the rango application
url(r'^admin/', admin.site.urls),
]
rango.urls.py
from django.conf.urls import url
from rango import views
urlpatterns = [
url(r'^rango/', views.index, name='index'),
url(r'$^rango/about/',views.about,name='about'),
]
rango.views.py
from django.http import HttpResponse
def index(request):
return HttpResponse("Rango says hey there partner! \
<br/> <a href='/rango/about/'>about</a>")
def about(request):
return HttpResponse("Rango says here is the about page. \
<br/> <a href='/rango/'>index</a>")
# rango.urls.py
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^about/$',views.about,name='about'),
]
I am using djangos include feature in my main urls file, from my app urls file.
main urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^posts/', include('posts.urls')),
]
posts.urls.py
from django.conf.urls import url
from . import views #relative import to post views
urlpatterns = [
url(r'$',"views.posts_list" ), #list all posts
url(r'create/$',"views.posts_create" ),
url(r'detail/$',"views.posts_detail" ),
url(r'update/$',"views.posts_update" ),
url(r'delete/$',"views.posts_delete" ),
]
here is the error:
raise TypeError('view must be a callable or a list/tuple in the case of include().')
TypeError: view must be a callable or a list/tuple in the case of include().
I have looked at the docs on this issue:
https://docs.djangoproject.com/en/1.11/ref/urls/#include
and the source code:
https://docs.djangoproject.com/en/1.11/_modules/django/conf/urls/#include
and I have no idea what I am doing wrong.
Please help. Hugs kisses, and high fives
Django 1.10+ no longer allows you to specify views as a string (e.g. 'myapp.views.index') in your URL patterns.
So you should config your posts urls.py like this:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.posts_list, name='list'),
url(r'^create/$', views.posts_create, name='create'),
url(r'^detail/$', views.posts_detail, name='detail'),
url(r'^update/$', views.posts_update, name='update'),
url(r'^delete/$', views.posts_delete, name='delete'),
]
It is also a good practice to add name to your urls.
Okay... let's try to explain things clearly. I've used Python Django to create a dynamic webpage/web-app. After completing the website I have published it using DigitalOcean and have successfully attached my purchased domain name to the name server of DigitalOcean. When I access my website, ordinanceservices.com, i get an error 404; however, if I type ordinanceservices.com/home it works as it should and displays the home page. How, by editing the python files, can I have it to where ordinanceservices.com will display the home page as opposed to error 404? I feel like there's something that I am doing that is fundamentally wrong regarding my .urls structure and thus a rewrite/redirect in the nginx config should not be necessary.
Here is the specific error:
Page not found (404)
Request Method: GET
Request URL: http://ordinanceservices.com/
Using the URLconf defined in django_project.urls, Django tried these URL patterns, in this order:
^admin/
^ ^home/ [name='home']
^ ^contact/ [name='contact']
^ ^services/ [name='services']
The current URL, , didn't match any of these.
I somewhat understand what is happening here though I do not know how to fix this. Next I will provide my .urls files for each folder that contains such:
/django_project urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('company.urls')),
)
/company urls.py
from django.conf.urls import url, include
from . import views
urlpatterns = [
url(r'^home/', views.home, name='home'),
url(r'^contact/', views.contact, name='contact'),
url(r'^services/', views.services, name='services'),
]
/company views.py
from django.shortcuts import render
def home(request):
return render(request, 'company/home.html')
def contact(request):
return render(request, 'company/contact.html')
def services(request):
return render(request, 'company/services.html')
What I am aiming to do, without needing to redirect the main URL using the nginx config files to do so, is to edit my urls and views structure of my Python files to ensure that the normal URL, ordinanceservices.com, will actually display a page; preferably the home page of my webpage.
I have a hunch that it has to do with the fact that I do not have a views.index for the r'^admin/' to reach to. I am not certain but I have been trying to figure this out for hours. Does anyone have a clue what I can do to fix this?
You haven't defined anything at the root url. Add one more line to your company urls.py so it becomes
//company urls.py
from django.conf.urls import url, include
from . import views
urlpatterns = [
url(r'^$', views.home, name='home'),
url(r'^home/', views.home, name='home'),
url(r'^contact/', views.contact, name='contact'),
url(r'^services/', views.services, name='services'),
]
First of all, check if you have added www.yourdomain.com or yourdomain.com to ALLOWED_HOST = ['www.yourdomain.com','yourdomain.com'] in your settings.py
and then in your company/urls.py do this
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.home, name='home'),
url(r'^contact/$', views.contact, name='contact'),
url(r'^services/$', views.services, name='services'),
]
and in your main urls.py add this code
from django.conf.urls import url,include
from django.contrib import admin
admin.autodiscover()
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('company.urls')),
]
I'm trying out Python Django. With eclipse pyDev. But I'm unable to simply get my first url to display.
This urls.py is from the Cr package.
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index')
]
This urlspy is from the Crowd package.
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'Crowd/', include('Cr.urls'))
]
So what I've understood from this the Crowd package is the "main" webservice(?), and by using include I can whenever the regular expression matches Crowd, will pass it on to the other urls.py(Cr). But the debugger passes:
Using the URLconf defined in Crowd.urls, Django tried these URL patterns, in this order:
^admin/
The current URL, crowd, didn't match any of these.
my views.py file
from django.shortcuts import HttpResponse
def index(request):
return HttpResponse('<h1>Hello World!</h1>')
I tried to access it with http://127.0.0.1:8000/Crowd
Below is an image of the project folder.
Can we see your settings.py file? There is a place in there where you define your project's url file. I'm assuming it's right now either not there or it's pointing to the wrong place, because Django can't find your urls.py file.
For example, in my settings.py file for one of my projects, I have:
ROOT_URLCONF = 'Freya.urls'
Where "Freya" is my project name
Just for reference, not that I know this will solve your problem, this is what (part of) my urls.py file looks like for one of my projects:
from django.conf.urls import patterns, url
import views
urlpatterns = patterns(
'',
url(r'^$', views.index, name='index'),
url(r'^login/$', views.login, name='login'),
url(r'^logout/$', views.logout, name='logout'),
)
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'Crowd/', include('Cr.urls'))
]
just use this urls.py file