首页 > 解决方案 > Django 2.1.1 'set' 对象不可逆'set' 对象是

问题描述

这基本上是我得到的错误

商店/网址

#/shop/
from django.urls import path`enter code here
from . import views

app_name='shop'

urlpatterns = [
    path('', views.allProdCat, name='allProdCat'),
    path('<slug:c_slug>/', views.allProdCat, name='products_by_category'),
    path('<slug:c_slug>/<slug:product_slug>/', views.ProdCatDetail, name='ProdCatDetail'),
]

商店/模板/商店/标题

{% load staticfiles %}
<header>
    <center>
        <a href="{% url 'shop:allProdCat' %}"><img class ='zapp-logo' src="{% static 'img/zapp_banner.jpg' %}" alt="Logo "></a>
    </center>
</header>

经过一些搜索,没有找到任何解决方案。有谁知道这个问题?

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

编辑 :

main/shop/templates/shop/base.html(标题扩展自)

{% load staticfiles %}
<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="{% block metadescription %}{% endblock %}">
    <link rel="stylesheet" href="{% static 'css/custom.css' %}">
    <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
    <link rel="stylesheet" href="{% static 'css/all.css' %}">
    <title>{% block title %}{% endblock %}</title>
</head>
<body>
    <div class='container'>
        {% include 'shop/header.html' %}
        {% include 'shop/navbar.html' %}
        {% block content %}
        {% endblock %}
    </div>
        {% include 'shop/footer.html' %}
    <script src="{% static 'js/jquery-3.3.1.slim.min.js' %}"></script>
    <script src="{% static 'js/popper.min.js' %}"></script>
    <script src="{% static 'js/bootstrap.min.js' %}"></script>
</body>
</html>

主要/网址

urlpatterns = [
    path('admin/', admin.site.urls),
    path('shop/', include('shop.urls')),
    path('cart/', include('cart.urls')),
]

if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

主要/设置(某些部分)

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'shop',
    'cart',
]
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'shop', 'templates/'), os.path.join(BASE_DIR, 'cart', 'templates/')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'shop.context_processor.menu_links'
            ],
        },
    },
]

标签: djangodjango-templatesdjango-views

解决方案


推荐阅读