2

I was using Django import-export app and now I want to add Grappelli in order to improve the Admin interface. I'm getting an error related to the templates. Any suggestion to get them work together?

Error:

Environment:


Request Method: GET
Request URL: http://localhost:8000/admin/db_personal/personalinstituto/

Django Version: 1.7c1
Python Version: 2.7.8
Installed Applications:
('grappelli',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'import_export',
 'db_personal')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Template error:
In template C:\Gestion AI2\web_nueva\templates\admin\change_list.html, error at line 1
   maximum recursion depth exceeded in __instancecheck__
   1 :  {% extends "admin/change_list.html" %} 


   2 : 


   3 : {# Original template renders object-tools only when has_add_permission is True. #}


   4 : {# This hack allows sub templates to add to object-tools #}


   5 : {% block object-tools %}


   6 :   <ul class="object-tools">


   7 :     {% block object-tools-items %}


   8 :       {% if has_add_permission %}


   9 :         {{ block.super }}


   10 :       {% endif %}


   11 :     {% endblock %}
4

4 回答 4

1

好吧,我认为您的问题不在模板脚本中,而是在扩展中。您的模板尝试扩展自身。

templates\admin\change_list.html,第 1 行错误 1 ​​: {% extends "admin/change_list.html" %}

admin/change_list.html 指的是基本的 django 模板 change_list。您的 django-import-export change_list 模板似乎具有相同的路径。来自 django-import-export 的 change_list 模板应该在 template/admin/ import_export /change_list.html

于 2015-04-13T13:07:35.807 回答
0

我很好地将它们一起使用。我不得不在 admin/includes_grappelli/header.html 中更改它:

-                    {% url admin:password_change as password_change_url %}
+                    {% url 'admin:password_change' as password_change_url %}

-                    {% url admin:logout as logout_url %}
+                    {% url 'admin:logout' as logout_url %}

-                {% url test-index as testindexurl %}
+                {% url 'test-index' as testindexurl %}

-                {% url django-admindocs-docroot as docsroot %}
+                {% url 'django-admindocs-docroot' as docsroot %}

并使用 ImportExportActionModelAdmin 调用它以避免 CSS 问题。

from import_export.admin import ImportExportActionModelAdmin

class MyModelAdmin(ImportExportActionModelAdmin):
    """
    Admin class for MyModel model
    """
    form = MyModelAdminForm

    list_display = ()
    ordering = []

    resource_class = MyModelResource

希望能帮助到你...

于 2015-03-06T08:05:30.353 回答
0

我刚刚遇到了同样的问题,这里有一个更一步一步的方法。

在您的项目中为 import_export 模板创建一个目录,并为 change_list_import 模板添加一个 html 文件。

myproj
├── myproj
│   ├──url.py
│   ├──settings.py
├── manage.py
├── db_personal #myapp
│   ├── admin.py
│   ├── models.py
|   ├── viewss.py
├── templates
|   ├── admin
|   |   ├── import_export
|   |   |   ├── change_list_import.html 
├── dashboard.py

接下来,将以下代码复制到此模板 html 文件中。请注意,它需要扩展 grappelli 更改列表模板,因此引用此模板的位置:

{% extends "C:/Python27/lib/site-packages/grappelli/templates/admin/change_list.html" %}
{% load i18n %}

{% block object-tools-items %}
   <li><a href="import/" class="import_link">{% trans "Import" %}</a></li>
   {{ block.super }}
{% endblock %}
于 2015-05-25T10:50:10.387 回答
0

grappelli 需要在 INSTALLED_APPS 中的 import_export 之前。

引用自 https://django-grappelli.readthedocs.io/en/latest/thirdparty.html

于 2020-03-05T08:41:05.213 回答