I have this link with url:
See More
It is directing it to this url pattern for my app:
from django.conf.urls import url
from listings import views
app_name = 'listings'
urlpatterns = [
url(r'^$',views.UniversityListView.as_view(),name='universities'),
url(r'^/(?P<name_initials>\w+)$',views.ListingView.as_view(),name='listing_detail'),
]
Here are the project url patterns to go along with it:
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$',views.HomeView.as_view(),name='index'),
url(r'^(?P<u_slug>[-\w]+)/$',views.UniversityHomePageView.as_view(),name='university_homepage'),
url(r'^(?P<u_slug>[-\w]+)/',include('listings.urls',namespace='listings')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
However I am getting this error:
django.urls.exceptions.NoReverseMatch: Reverse for 'listing_detail' with arguments '('stafford-apartments',)' not found. 1 pattern(s) tried: ['(?P<u_slug>[-\\w]+)//(?P<name_initials>\\w+)$']
Django: 1.11
Edit:
Here is the detail view:
class ListingView(DetailView):
model = Listing
company = Company.objects.all()
university = University.objects.all()
context = {
'listing':model,
'company':company,
'university':university,
}
As the error says, your listing_detail URL requires two arguments - u_slug and name_initials - but you are only providing one.
Related
i'm building my first Django app so i'm know i'm missing a lot of things, but i installed a gallery for my site and is inside site-packages, i set the url inside urls.py and it looks like this :
from django.contrib import admin
from django.urls import path,include
from django.conf import settings
from django.conf.urls.static import static
from contacto.views import Home,Contacto
urlpatterns = [
path('admin/', admin.site.urls),
path('gallery/', include('gallery.urls'),name='gallery'),
path('home/',Home,name='home'),
path('contacto/',Contacto,name='contacto')
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
I can perfectly access the gallery and its functionalities if i write the url in the browser, but i cannot reference the gallery Url inside my template like the other Urls using {% url 'gallery' %}, i keep getting this error :
Reverse for 'gallery' not found. 'gallery' is not a valid view function or pattern name.
Also heres the gallery url:
from django.urls import path
from gallery.views import ImageView, ImageList, AlbumView, AlbumList, ImageCreate
app_name = 'gallery'
urlpatterns = [
path('', AlbumList.as_view(), name='album_list'),
path('images/', ImageList.as_view(), name='image_list'),
path('image/<int:pk>/<slug>', ImageView.as_view(), name='image_detail'),
path('upload/', ImageCreate.as_view(), name='image_upload'),
path('album/<int:pk>/<slug>/', AlbumView.as_view(), name='album_detail'),
path('album/<int:apk>/<int:pk>/<slug>', ImageView.as_view(), name='album_image_detail')
]
Thanks!
app_name = 'gallery'
urlpatterns = [
path('admin/', admin.site.urls),
path('gallery/', include('gallery.urls')),
path('home/',Home,name='home'),
path('contacto/',Contacto,name='contacto')
]
Change it as shown above and call gallery:album_list for album list, and follow same pattern for others
I am getting the above error when I try to access the landing page.
What am I missing?
Traceback
NoReverseMatch at /
Reverse for 'fleet' not found. 'fleet' is not a valid view function or pattern name.
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 2.2.6
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'fleet' not found. 'fleet' is not a valid view function or pattern name.
Here is the base.html code
<button>
` Fleet Admin
</button>
and below is the app urls.py file
from django.urls import path
from .admin import fleet_admin_site
app_name = 'trucks'
urlpatterns = [
path('fleet/', fleet_admin_site.urls, name="fleet"),
]
and the main urls.py file
from django.contrib import admin
from django.urls import path, include, reverse
from django.views.generic import TemplateView
urlpatterns = [
path('admin/', include('workers.urls')),
path('admin/', include('trucks.urls')),
path('', TemplateView.as_view(template_name='base.html')),
]
admin.py file where I extend the AdminSite
class FleetAdminSite(admin.AdminSite):
site_header = ''
site_title = ''
index_title = ''
fleet_admin_site = FleetAdminSite(name='fleet_admin')
by seeing your code
you need to add method or class not any extension
path('fleet/', fleet_admin_site.urls, name="fleet"),
path(route, view, kwargs=None, name=None)
refer this
You are including the fleet admin with:
urlpatterns = [
path('fleet/', fleet_admin_site.urls, name="fleet"),
]
You can't do {% url 'trucks:fleet' %} to reverse fleet_admin_site.urls. You need to reverse a particular admin URL.
For example, to reverse the index, you would do:
{% 'trucks:fleet_admin:index' %}
In the above, you use trucks because you have app_name = 'trucks' in the urls.py, fleet_admin because that is the namespace in fleet_admin_site = FleetAdminSite(name='fleet_admin'), and index because that's the view you want to reverse.
Finally, the name in your path() doesn't have any effect, so I would remove it.
urlpatterns = [
path('fleet/', fleet_admin_site.urls),
]
I'm giving Python / Django a ago, going alright so far. I'm in the middle of setting up Django authentication, but I've hit a error;
Reverse for 'user_review_list' not found. 'user_review_list' is not a valid view function or pattern name.
Here are my views:
def user_review_list(request, username=None):
if not username:
username = request.user.username
latest_review_list = Review.objects.filter(user_name=username).order_by('-pub_date')
context = {'latest_review_list':latest_review_list, 'username':username}
return render(request, 'reviews/user_review_list.html', context)
In my base.html I call the following:
<li><a href="{% url 'reviews:user_review_list' user.username %}">Hello {{ user.username }}</li>
I've checked my other html templates and they all seem to be calling it correctly, is there anything I'm missing?
EDIT: URL's
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^reviews/', include(('reviews.urls', 'reviews'), namespace='reviews')),
url(r'^admin/', admin.site.urls),
url(r'^accounts/', include('registration.backends.simple.urls')),
url(r'^accounts/', include('django.contrib.auth.urls')),
]
Apps URL's
from django.conf.urls import url
from . import views
app_name = 'reviews'
urlpatterns = [
# ex: /
url(r'^$', views.review_list, name='review_list'),
# ex: /product/5/
url(r'^review/(?P<review_id>[0-9]+)/$', views.review_detail, name='review_detail'),
# ex: /product/
url(r'^product$', views.product_list, name='product_list'),
# ex: /product/5/
url(r'^product/(?P<product_id>[0-9]+)/$', views.product_detail, name='product_detail'),
url(r'^product/(?P<product_id>[0-9]+)/add_review/$', views.add_review, name='add_review'),
]
Review.objects.filter() will return a list.
For a single user, you should use Review.objects.get() method
As #Exprator pointed out I was missing user_review_list from my app URL's.
I'm trying to make a web server with Django for making "parrot bot".
I'm using
python3.5
Django
apache2.4
The error I'm getting :
Page not found (404)
Request Method: GET
Request URL: http://54.95.30.145/
Using the URLconf defined in bot.urls, Django tried these URL patterns, in this order:
^keyboard/
^message
The empty path didn't match any of these.
This is my project bot/urls.py code.
from django.conf.urls import url, include
urlpatterns = [
url(r'',include('inform.urls')),
]
This is my app inform/urls.py code.
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^keyboard/',views.keyboard),
url(r'^message',views.message),
]
This is my inform/views.py code.
from django.http import JsonResponse
def keyboard(request):
return JsonResponse({
'type' : 'text',
})
def message(request):
message = ((request.body).decode('utf-8'))
return_json_str = json.loads(message)
return_str = return_json_str['contetn']
return JsonResponse({
'message': {
'text' : return_str
}
})
Please help me.
It error is nothing but you didn't define any url patterns for your root address (http://54.95.30.145/).
To solve this, add a url pattern for home/root address as below in project bot/urls.py
from django.conf.urls import url, include
def root_view(request):
return JsonResponse({"message": "This is root"})
urlpatterns = [
url(r'^$', root_view),
url(r'', include('inform.urls')),
]
I'm getting this error:
NoReverseMatch at /genomics/ Reverse for 'pipelinedetail' with
arguments '('02152ad7-8399-441c-ba8f-f8871460cd5f',)' and keyword
arguments '{}' not found. 0 pattern(s) tried: []
When I navigate to this URL:
http://127.0.0.1:8000/genoa/
My genoa_urls.py has:
urlpatterns = [
# ex: /polls/samples
url(r'^$', views.samples, name='samples'),
url(r'^(?P<sequence_id>[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})/pipelinedetail/$', views.pipelinedetail, name='pipelinedetail'),
]
The offending line in my template is:
<td>JSON</td>
And my view contains:
def pipelinedetail(request, sequence_id):
# sequence_id = '7e6bd861-934f-44be-872a-b59826107bda'
sample = get_object_or_404(Sample, pk=sequence_id)
sample_details = sample.values('pipeline_detail')
context = {'sample_details': sample_details}
return render(request, 'polls/pipelinedetail.html', context)
Here's the top level urls.py:
urlpatterns = [
# polls in the url maps to polls.urls.py
url(r'^polls/', include('polls.urls')),
url(r'^genoa/', include('polls.genoa_urls')),
url(r'^admin/', admin.site.urls),
]
What am I doing wrong?
Your polls URLs are not in a namespace, so you don't need the prefix.
{% url 'pipelinedetail' me.sequence_id %}
Both of your suggestions ultimately worked as did my original code once I created a new app and placed my new code there. Thank you.