Django - 在调用Python对象时超过了最大递归深度。

问题描述 投票:-1回答:1

错误回溯 - 由于字符限制,删除了一些或多或少无用的路径......。

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/

Django Version: 3.0.6
Python Version: 3.8.2
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'core',
 'leads']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']


Template error:
In template /home/radu/Documents/work/ProtocolV6/protocol/core/templates/base_generic.html, error at line 57
   maximum recursion depth exceeded while calling a Python object
   47 :       href="plugins/owl.carousel/dist/assets/owl.carousel.min.css"
   48 :     />
   49 :     <link
   50 :       rel="stylesheet"
   51 :       href="plugins/owl.carousel/dist/assets/owl.theme.default.min.css"
   52 :     />
   53 :     <link rel="stylesheet" href="dist/css/theme.min.css" />
   54 :   </head>
   55 : 
   56 :   <body>
   57 :      {% include "header.html" %}  {% include "header.html" %} {% block content %}
   58 :     {% endblock %}
   59 :   </body>
   60 : </html>
   61 : 

Traceback (most recent call last):
  File "/home/radu/.local/share/virtualenvs/ProtocolV6-LVs3tHy5/lib/python3.8/site-packages/django/template/base.py", line 765, in __init__
    self.literal = float(var)

During handling of the above exception (could not convert string to float: '"header.html"'), another exception occurred:
  File "/home/radu/.local/share/virtualenvs/ProtocolV6-LVs3tHy5/lib/python3.8/site-packages/django/template/base.py", line 903, in render_annotated
    return self.render(context)
  File "/home/radu/.local/share/virtualenvs/ProtocolV6-LVs3tHy5/lib/python3.8/site-packages/django/template/loader_tags.py", line 127, in render
    compiled_parent = self.get_parent(context)
  File "/home/radu/.local/share/virtualenvs/ProtocolV6-LVs3tHy5/lib/python3.8/site-packages/django/template/loader_tags.py", line 124, in get_parent
    return self.find_template(parent, context)
  File "/home/radu/.local/share/virtualenvs/ProtocolV6-LVs3tHy5/lib/python3.8/site-packages/django/template/loader_tags.py", line 103, in find_template
    template, origin = context.template.engine.find_template(
  File "/home/radu/.local/share/virtualenvs/ProtocolV6-LVs3tHy5/lib/python3.8/site-packages/django/template/engine.py", line 125, in find_template
    template = loader.get_template(name, skip=skip)
  File "/home/radu/.local/share/virtualenvs/ProtocolV6-LVs3tHy5/lib/python3.8/site-packages/django/template/loaders/base.py", line 29, in get_template
    return Template(
  File "/home/radu/.local/share/virtualenvs/ProtocolV6-LVs3tHy5/lib/python3.8/site-packages/django/template/base.py", line 156, in __init__
    self.nodelist = self.compile_nodelist()
  File "/home/radu/.local/share/virtualenvs/ProtocolV6-LVs3tHy5/lib/python3.8/site-packages/django/template/base.py", line 194, in compile_nodelist
    return parser.parse()
  File "/home/radu/.local/share/virtualenvs/ProtocolV6-LVs3tHy5/lib/python3.8/site-packages/django/template/base.py", line 477, in parse
    raise self.error(token, e)
  File "/home/radu/.local/share/virtualenvs/ProtocolV6-LVs3tHy5/lib/python3.8/site-packages/django/template/base.py", line 475, in parse
    compiled_result = compile_func(self, token)
  File "/home/radu/.local/share/virtualenvs/ProtocolV6-LVs3tHy5/lib/python3.8/site-packages/django/template/loader_tags.py", line 316, in do_include
    return IncludeNode(parser.compile_filter(bits[1]), extra_context=namemap,
  File "/home/radu/.local/share/virtualenvs/ProtocolV6-LVs3tHy5/lib/python3.8/site-packages/django/template/base.py", line 562, in compile_filter
    return FilterExpression(token, self)
  File "/home/radu/.local/share/virtualenvs/ProtocolV6-LVs3tHy5/lib/python3.8/site-packages/django/template/base.py", line 640, in __init__
    var_obj = Variable(constant).resolve({})
  File "/home/radu/.local/share/virtualenvs/ProtocolV6-LVs3tHy5/lib/python3.8/site-packages/django/template/base.py", line 781, in __init__
    self.literal = mark_safe(unescape_string_literal(var))
  File "/home/radu/.local/share/virtualenvs/ProtocolV6-LVs3tHy5/lib/python3.8/site-packages/django/utils/functional.py", line 204, in wrapper
    if any(isinstance(arg, Promise) for arg in itertools.chain(args, kwargs.values())):
  File "/home/radu/.local/share/virtualenvs/ProtocolV6-LVs3tHy5/lib/python3.8/site-packages/django/utils/functional.py", line 204, in <genexpr>
    if any(isinstance(arg, Promise) for arg in itertools.chain(args, kwargs.values())):

Exception Type: RecursionError at /
Exception Value: maximum recursion depth exceeded while calling a Python object

视图.py

from django.shortcuts import render
from .models import Contact
from django.views import generic


def index(request):
    """View function for home page of site."""

    # Generate counts of some of the main objects
    contacts = Contact.objects.all()

    context = {
        'contacts': contacts,
    }

    # Render the HTML template index.html with the data in the context variable
    return render(request, 'index.html', context=context)

模型

from django.db import models
from django.urls import reverse
#from datetime import date
#from django.contrib.auth.models import User


class Contact(models.Model):
    contact_title = models.CharField(max_length=50, help_text='Title')
    contact_first_name = models.CharField(max_length=50,
                                          help_text='First Name')
    contact_middle_name = models.CharField(max_length=50,
                                           help_text='Middle Name',
                                           null=True)
    contact_last_name = models.CharField(max_length=50, help_text='Last Name')
    contact_date_of_initial_contact = models.DateTimeField(auto_now_add=True,
                                                           unique=True)
    contact_company = models.CharField(max_length=200,
                                       help_text="Contact's Company",
                                       null=True)
    contact_industry = models.CharField(max_length=200,
                                        help_text="Contact's Industry",
                                        null=True)
    contact_address = models.CharField(max_length=200, help_text='Address')
    contact_address_street = models.CharField(max_length=200,
                                              help_text='Street')
    contact_address_city = models.CharField(max_length=200, help_text='City')
    contact_address_state = models.CharField(max_length=200, help_text='State')
    contact_address_zip = models.CharField(max_length=200,
                                           help_text='Zip',
                                           null=True)
    contact_address_country = models.CharField(max_length=200,
                                               help_text='Country')
    contact_phone = models.CharField(max_length=200, help_text='State')
    contact_email = models.EmailField(unique=True)
    contact_website = models.URLField(null=True)
    contact_facebook = models.URLField(null=True)
    contact_instagram = models.URLField(null=True)
    contact_twitter = models.URLField(null=True)
    contact_linkedin = models.URLField(null=True)
    contact_github = models.URLField(null=True)
    contact_description = models.TextField(max_length=1000, null=True)
    contact_budget = models.IntegerField()
    contact_request = models.TextField(
        max_length=1000, help_text='Type here what the contact requestsed')
    contact_sales_rep = models.CharField(max_length=200,
                                         help_text='Sales Rep.')
    contact_created_on = models.DateTimeField(auto_now_add=True, unique=True)
    contact_date_of_birth = models.DateField(null=True, blank=True)
    language_name = models.CharField(max_length=200,
                                     help_text="Enter the book's natural language (e.g. English, French, Japanese etc.)", null=True)

    class Meta:
        ordering = ['contact_last_name', 'contact_first_name']

    def __str__(self):
        """String for representing the Model object."""
        return self.contact_first_name

    def get_absolute_url(self):
        """Returns the url to access a detail record for this book."""
        return reverse('contact-detail', args=[str(self.id)])

基础Html

<!DOCTYPE html>
<html class="no-js" lang="en">
  <head>
    {% block title %}

    <title>Protocol CRM</title>

    {% endblock %}
    <meta charset="utf-8" />
    <meta http-equiv="x-ua-compatible" content="ie=edge" />
    <meta name="description" content="" />
    <meta name="keywords" content="" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link
      href="https://fonts.googleapis.com/css?family=Nunito+Sans:300,400,600,700,800"
      rel="stylesheet"
    />
    {% load static %}
    <link rel="icon" href="favicon.ico" type="image/x-icon" />
    <link
      rel="stylesheet"
      href="plugins/bootstrap/dist/css/bootstrap.min.css"
    />
    <link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css" />
    <link rel="stylesheet" href="plugins/icon-kit/dist/css/iconkit.min.css" />
    <link rel="stylesheet" href="plugins/ionicons/dist/css/ionicons.min.css" />
    <link
      rel="stylesheet"
      href="plugins/perfect-scrollbar/css/perfect-scrollbar.css"
    />
    <link
      rel="stylesheet"
      href="plugins/datatables.net-bs4/css/dataTables.bootstrap4.min.css"
    />
    <link rel="stylesheet" href="plugins/jvectormap/jquery-jvectormap.css" />
    <link
      rel="stylesheet"
      href="plugins/tempusdominus-bootstrap-4/build/css/tempusdominus-bootstrap-4.min.css"
    />
    <link
      rel="stylesheet"
      href="plugins/weather-icons/css/weather-icons.min.css"
    />
    <link rel="stylesheet" href="plugins/c3/c3.min.css" />
    <link
      rel="stylesheet"
      href="plugins/owl.carousel/dist/assets/owl.carousel.min.css"
    />
    <link
      rel="stylesheet"
      href="plugins/owl.carousel/dist/assets/owl.theme.default.min.css"
    />
    <link rel="stylesheet" href="dist/css/theme.min.css" />
  </head>

  <body>
    {% include "header.html" %} {% include "header.html" %} {% block content %}
    {% endblock %}
  </body>
</html>

标题模板

{% extends "base_generic.html" %} {% load static %} {% block content %}

<header class="header-top" header-theme="light">
  <div class="container-fluid">
    <div class="d-flex justify-content-between">
      <div class="top-menu d-flex align-items-center">
        <button type="button" class="btn-icon mobile-nav-toggle d-lg-none">
          <span></span>
        </button>
        <div class="header-search">
          <div class="input-group">
            <span class="input-group-addon search-close"
              ><i class="ik ik-x"></i
            ></span>
            <input type="text" class="form-control" />
            <span class="input-group-addon search-btn"
              ><i class="ik ik-search"></i
            ></span>
          </div>
        </div>
        <button type="button" id="navbar-fullscreen" class="nav-link">
          <i class="ik ik-maximize"></i>
        </button>
      </div>
      <div class="top-menu d-flex align-items-center">
        <div class="dropdown">
          <a
            class="nav-link dropdown-toggle"
            href="#"
            id="notiDropdown"
            role="button"
            data-toggle="dropdown"
            aria-haspopup="true"
            aria-expanded="false"
            ><i class="ik ik-bell"></i><span class="badge bg-danger">3</span></a
          >
          <div
            class="dropdown-menu dropdown-menu-right notification-dropdown"
            aria-labelledby="notiDropdown"
          >
            <h4 class="header">Notifications</h4>
            <div class="notifications-wrap">
              <a href="#" class="media">
                <span class="d-flex">
                  <i class="ik ik-check"></i>
                </span>
                <span class="media-body">
                  <span class="heading-font-family media-heading"
                    >Invitation accepted</span
                  >
                  <span class="media-content">Your have been Invited ...</span>
                </span>
              </a>
              <a href="#" class="media">
                <span class="d-flex">
                  <img src="#" class="rounded-circle" alt="" />
                </span>
                <span class="media-body">
                  <span class="heading-font-family media-heading"
                    >Steve Smith</span
                  >
                  <span class="media-content">I slowly updated projects</span>
                </span>
              </a>
              <a href="#" class="media">
                <span class="d-flex">
                  <i class="ik ik-calendar"></i>
                </span>
                <span class="media-body">
                  <span class="heading-font-family media-heading">To Do</span>
                  <span class="media-content"
                    >Meeting with Nathan on Friday 8 AM ...</span
                  >
                </span>
              </a>
            </div>
            <div class="footer">
              <a href="javascript:void(0);">See all activity</a>
            </div>
          </div>
        </div>
        <button type="button" class="nav-link ml-10 right-sidebar-toggle">
          <i class="ik ik-message-square"></i
          ><span class="badge bg-success">3</span>
        </button>
        <div class="dropdown">
          <a
            class="nav-link dropdown-toggle"
            href="#"
            id="menuDropdown"
            role="button"
            data-toggle="dropdown"
            aria-haspopup="true"
            aria-expanded="false"
            ><i class="ik ik-plus"></i
          ></a>
          <div
            class="dropdown-menu dropdown-menu-right menu-grid"
            aria-labelledby="menuDropdown"
          >
            <a
              class="dropdown-item"
              href="#"
              data-toggle="tooltip"
              data-placement="top"
              title="Dashboard"
              ><i class="ik ik-bar-chart-2"></i
            ></a>
            <a
              class="dropdown-item"
              href="#"
              data-toggle="tooltip"
              data-placement="top"
              title="Message"
              ><i class="ik ik-mail"></i
            ></a>
            <a
              class="dropdown-item"
              href="#"
              data-toggle="tooltip"
              data-placement="top"
              title="Accounts"
              ><i class="ik ik-users"></i
            ></a>
            <a
              class="dropdown-item"
              href="#"
              data-toggle="tooltip"
              data-placement="top"
              title="Sales"
              ><i class="ik ik-shopping-cart"></i
            ></a>
            <a
              class="dropdown-item"
              href="#"
              data-toggle="tooltip"
              data-placement="top"
              title="Purchase"
              ><i class="ik ik-briefcase"></i
            ></a>
            <a
              class="dropdown-item"
              href="#"
              data-toggle="tooltip"
              data-placement="top"
              title="Pages"
              ><i class="ik ik-clipboard"></i
            ></a>
            <a
              class="dropdown-item"
              href="#"
              data-toggle="tooltip"
              data-placement="top"
              title="Chats"
              ><i class="ik ik-message-square"></i
            ></a>
            <a
              class="dropdown-item"
              href="#"
              data-toggle="tooltip"
              data-placement="top"
              title="Contacts"
              ><i class="ik ik-map-pin"></i
            ></a>
            <a
              class="dropdown-item"
              href="#"
              data-toggle="tooltip"
              data-placement="top"
              title="Blocks"
              ><i class="ik ik-inbox"></i
            ></a>
            <a
              class="dropdown-item"
              href="#"
              data-toggle="tooltip"
              data-placement="top"
              title="Events"
              ><i class="ik ik-calendar"></i
            ></a>
            <a
              class="dropdown-item"
              href="#"
              data-toggle="tooltip"
              data-placement="top"
              title="Notifications"
              ><i class="ik ik-bell"></i
            ></a>
            <a
              class="dropdown-item"
              href="#"
              data-toggle="tooltip"
              data-placement="top"
              title="More"
              ><i class="ik ik-more-horizontal"></i
            ></a>
          </div>
        </div>
        <button
          type="button"
          class="nav-link ml-10"
          id="apps_modal_btn"
          data-toggle="modal"
          data-target="#appsModal"
        >
          <i class="ik ik-grid"></i>
        </button>
        <div class="dropdown">
          <a
            class="dropdown-toggle"
            href="#"
            id="userDropdown"
            role="button"
            data-toggle="dropdown"
            aria-haspopup="true"
            aria-expanded="false"
            ><img class="avatar" src="img/user.jpg" alt=""
          /></a>
          <div
            class="dropdown-menu dropdown-menu-right"
            aria-labelledby="userDropdown"
          >
            <a class="dropdown-item" href="profile.html"
              ><i class="ik ik-user dropdown-icon"></i> Profile</a
            >
            <a class="dropdown-item" href="#"
              ><i class="ik ik-settings dropdown-icon"></i> Settings</a
            >
            <a class="dropdown-item" href="#"
              ><span class="float-right"
                ><span class="badge badge-primary">6</span></span
              ><i class="ik ik-mail dropdown-icon"></i> Inbox</a
            >
            <a class="dropdown-item" href="#"
              ><i class="ik ik-navigation dropdown-icon"></i> Message</a
            >
            <a class="dropdown-item" href="#"
              ><i class="ik ik-power dropdown-icon"></i> Logout</a
            >
          </div>
        </div>
      </div>
    </div>
  </div>
</header>

{% endblock %}

我不知道为什么我得到这个错误。我正试图为我的crm做一个管理布局。我开始用一个基本的联系模型,我可以工作,然后试图添加一个头和siderbar从一个模板,我发现在网络上。但是,当我添加的头是给我这个... ... 请帮助我。

'核心'应用程序的url文件

from django.urls import path, include
from . import views

urlpatterns = [
    path('', views.core, name='core'),
]

和'协议'项目url文件

from django.contrib import admin
from django.urls import path, include

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


协议是项目的名称,核心是应用的名称。

python django templates django-templates crm
1个回答
0
投票

这个错误发生在当你包含 app.urls 内部。这听起来不像是一个好主意。 所以,检查你的。urls.py 再次。

© www.soinside.com 2019 - 2024. All rights reserved.