AttributeError: module 'import_export.admin' has no attribute 'site'
时间: 2023-09-10 15:12:34 浏览: 54
这个错误通常是由于在 Django 中使用了 `import_export` 库时未正确配置 `admin.py` 文件所导致的。请检查您的 `admin.py` 文件是否正确导入了 `import_export` 库并且正确配置了 `site.register()` 函数。以下是一个示例 `admin.py` 文件的代码:
```python
from django.contrib import admin
from import_export.admin import ImportExportModelAdmin
from .models import MyModel
class MyModelAdmin(ImportExportModelAdmin):
pass
admin.site.register(MyModel, MyModelAdmin)
```
请注意,您需要将 `MyModelAdmin` 继承自 `ImportExportModelAdmin`,这样才能实现导入和导出功能。如果您已经正确配置了 `admin.py` 文件,请确保在 Django 的 `INSTALLED_APPS` 设置中包含 `import_export` 库。
相关问题
AttributeError: module tensorflow.compat.v1 has no attribute contrib
AttributeError: module 'tensorflow.compat.v1' has no attribute 'contrib' 是由于TensorFlow版本更新导致的错误。在TensorFlow 2.0及以上版本中,contrib模块已被移除,因此无法使用。如果你的代码中使用了contrib模块,需要将其替换为TensorFlow 2.0及以上版本中的等效功能。
以下是一些可能有用的解决方法:
1. 尝试使用TensorFlow 1.x版本,或者升级代码以适应TensorFlow 2.0及以上版本。
2. 将代码中的contrib模块替换为TensorFlow 2.0及以上版本中的等效功能。
3. 检查代码中是否存在拼写错误或其他语法错误,这些错误可能会导致模块无法正确导入。
AttributeError: module 'blog.admin' has no attribute 'site'
AttributeError: module 'blog.admin' has no attribute 'site' 这个错误通常在Python编程中表示你尝试访问或调用`site`这个属性,但是该属性并不在`blog.admin`模块中定义。这可能意味着:
1. 你可能拼写错误了,检查一下`site`是否应该是`sites`,或者是否有其他正确的属性名。
2. `site`可能是一个只存在于某个特定上下文(如视图函数或配置文件)中的变量,而不是`blog.admin`模块本身的属性。
3. 如果你在继承自`admin.site`的类中使用这个属性,确保已经正确设置了继承关系并初始化了父类。
为了解决这个问题,你可以按照以下步骤操作:
- 检查代码中的import语句,确保`blog.admin`被正确导入。
- 确认`site`是否确实属于`blog.admin`,如果不是,查阅文档或查找正确的属性位置。
- 如果是在类定义中,确认你是否已经实例化了`admin.site`。
相关推荐
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)