/ provider /'provider'上的Django NoReverseMatch不是注册的名称空间

时间:2019-11-26 09:35:30

标签: python django

我正在学习Django,这是我的第一个项目,在尝试解决该问题的几天中,我都遇到了上述错误。如果我将空白html放上去,但下面的模板会出错

HTML文件在下面

{% extends 'base.html' %}

{% block body %}

    <!-- Products -->
    <div class="total-ads main-grid-border">
        <div class="container">
            <div class="select-box">
                <div class="browse-category ads-list">
                    <label>Browse Categories</label>
                    <select class="selectpicker show-tick" data-live-search="true">
                      <option data-tokens="Mobiles">All</option>
                      <option data-tokens="Mobiles">Mobiles</option>
                      <option data-tokens="Electronics & Appliances">Electronics & Appliances</option>
                      <option data-tokens="Cars">Cars</option>
                      <option data-tokens="Bikes">Bikes</option>
                      <option data-tokens="Furniture">Furniture</option>
                      <option data-tokens="Pets">Pets</option>
                      <option data-tokens="Books, Sports & Hobbies">Books, Sports & Hobbies</option>
                      <option data-tokens="Fashion">Fashion</option>
                      <option data-tokens="Kids">Kids</option>
                      <option data-tokens="Services">Services</option>
                      <option data-tokens="Jobs">Jobs</option>
                      <option data-tokens="Real Estate">Real Estate</option>
                    </select>
                </div>
                <div class="search-product ads-list">
                    <label>Search for a specific product</label>
                    <div class="search">
                        <div id="custom-search-input">
                        <div class="input-group">
                            <input type="text" class="form-control input-lg" placeholder="Buscar" />
                            <span class="input-group-btn">
                                <button class="btn btn-info btn-lg" type="button">
                                    <i class="glyphicon glyphicon-search"></i>
                                </button>
                            </span>
                        </div>
                    </div>
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="all-categories">
                <h3> Select your category and find the perfect ad</h3>
                <ul class="all-cat-list">



                </ul>
            </div>
            <ol class="breadcrumb" style="margin-bottom: 5px;">
              <li><a href="/">Home</a></li>
                <li class="active"><a active href="{% url 'provider:provider_list' %}> All Categories </a> </li>

                {% if category %}

                    <li class="active">{{category}} </li>
                {% endif%}
            </ol>
            <div class="ads-grid">
                <div class="side-bar col-md-3">
                    <div class="search-hotel">
                    <h3 class="sear-head">Search</h3>
                    <form method="GET" action="{% url 'provider : provider_list' %}">
                        <input type="text" value="Product name..."  name ="q" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Product name...';}" required="">
                        <input type="submit" value=" ">
                    </form>
                </div>


                <div class="featured-ads">
                    <h2 class="sear-head fer">Featured Ads</h2>
                    <div class="featured-ad">
                        <a href="single.html">
                            <div class="featured-ad-left">
                                <img src="images/f1.jpg" title="ad image" alt="" />
                            </div>
                            <div class="featured-ad-right">
                                <h4>Lorem Ipsum is simply dummy text of the printing industry</h4>
                                <p>$ 450</p>
                            </div>
                            <div class="clearfix"></div>
                        </a>
                    </div>
                    <div class="featured-ad">
                        <a href="single.html">
                            <div class="featured-ad-left">
                                <img src="images/f2.jpg" title="ad image" alt="" />
                            </div>
                            <div class="featured-ad-right">
                                <h4>Lorem Ipsum is simply dummy text of the printing industry</h4>
                                <p>$ 380</p>
                            </div>
                            <div class="clearfix"></div>
                        </a>
                    </div>
                    <div class="featured-ad">
                        <a href="single.html">
                            <div class="featured-ad-left">
                                <img src="images/f3.jpg" title="ad image" alt="" />
                            </div>
                            <div class="featured-ad-right">
                                <h4>Lorem Ipsum is simply dummy text of the printing industry</h4>
                                <p>$ 560</p>
                            </div>
                            <div class="clearfix"></div>
                        </a>
                    </div>
                    <div class="clearfix"></div>
                </div>
                </div>
                <div class="ads-display col-md-9">
                    <div class="wrapper">
                    <div class="bs-example bs-example-tabs" role="tabpanel" data-example-id="togglable-tabs">
                      <div id="myTabContent" class="tab-content">
                        <div role="tabpanel" class="tab-pane fade in active" id="home" aria-labelledby="home-tab">
                           <div>
                                                <div id="container">

                                <div class="clearfix"></div>
                            <ul class="list">

                                {%  for provider in provider_list  %}

                                    <a href="{%url 'provider : provider_detail' provider.slug %}">
                                        <li>
                                        <img src="{{provider.image.url}}" title="" alt="" />
                                        <section class="list-left">
                                        <h5 class="title">{{provider.name}}</h5>
                                        <span class="adprice"> Company </span>
                                        <p class="catpath">Mobile Phones » Brand</p>
                                        </section>
                                        <section class="list-right">
                                        <span class="date">Today, 17:55</span>
                                        <span class="cityname">City name</span>
                                        </section>
                                        <div class="clearfix"></div>
                                        </li>
                                    </a>

                                {% endfor %}
                             </ul>

                              </div>
                    </div>
                </div>
                </div>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>
    <!-- // Products -->

{% endblock body %}

views.py文件在下面

from django.shortcuts import render
from .models import Provider , ProviderImages ,Category
from django.db.models import Count
from django.db.models import Q
from django.shortcuts import get_object_or_404
from django.core.paginator import Paginator
# Create your views here.

def providerlist(request,category_slug = None):
    category = None
    providerlist = Provider.objects.all()
    categorylist = Category.objects.annotate(total_providers=Count('provider'))

    if category_slug:
        category= get_object_or_404(Category, slug = category_slug)
        providerlist = Category.filter(category=category)
    search_query = request.GET.get('q')
    if search_query :
        providerlist = providerlist.filter(
            Q(name__icontains=search_query) |
            Q(description__icontains=search_query)|
            Q(category__category__name__icontains  = search_query))

    template = 'provider/provider_list.html'

    context = {'provider_list': providerlist ,'category_list' : categorylist}

    return  render(request,template,context)


def providerdetail(request,provider_slug):
    #print(provider_slug)
    providerdetail=get_object_or_404(Provider,slug=provider_slug)
    providerimage =  ProviderImages.objects.filter(provider = providerdetail)
    template ='provider/provider_detail.html'
    context = {'provider_detail': providerdetail, 'provider_image' : providerimage}
    return render(request, template, context)

项目urls.py

from django.contrib import admin
from django.urls import path ,include
from django.conf import settings
from django.conf.urls.static import static


app_name = 'provider'
urlpatterns = [
    path('admin/', admin.site.urls),
    path('provider/', include('provider.urls',  namespace='provider')),
    ]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
'''

the app provider/urls.py
'''
from django.urls import path
from . import views

app_name = 'provider'
urlpatterns =[
    path('', views.providerlist , name='provider_list'),
    path('<slug: category_slug>', views.providerlist , name='provider_list_category'),
    path ('detail/<slug:provider_slug>',views.providerdetail, name='provider_detail')
]

我正在学习Django,这是我的第一个项目,在尝试解决该问题的几天中,我都遇到了上述错误。如果我将空白html放上去,但下面的模板会出错

0 个答案:

没有答案