当我尝试从管理员向数据库中添加一些数据时,出现 NoReverseMatch 错误
When I try to add some data in database from admin, Iam getting NoReverseMatch error
这里我没有使用任何管理模板。我正在使用默认的管理模板。我怎样才能扭转这个 url?
我得到的错误:
NoReverseMatch at /admin/machine/module/add/
Reverse for 'machine_module_change' with arguments '('',)' not found. 1 pattern(s) tried: ['admin/machine/module/(?P<object_id>.+)/change/$']
Request Method: POST
Request URL: http://localhost:8080/admin/machine/module/add/
Django Version: 3.0.8
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'machine_module_change' with arguments '('',)' not found. 1 pattern(s) tried: ['admin/machine/module/(?P<object_id>.+)/change/$']
Python Version: 3.7.7
Python Path:
['C:\Users\Administrator\Documents\CheckMeOut\checkmeout',
'C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python37.zip',
'C:\Users\Administrator\AppData\Local\Programs\Python\Python37\DLLs',
'C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib',
'C:\Users\Administrator\AppData\Local\Programs\Python\Python37',
'C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages',
'C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages',
'C:/Users/Administrator/Documents/CheckMeOut/checkmeout',
'C:/Users/Administrator/Documents/CheckMeOut/checkmeout/checkmeout']
Server time: Tue, 2 Mar 2021 15:21:42 +0530
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
from django.urls import reverse
urlpatterns = [
path('', include('main.urls')),
path('equipment/', include('equipment.urls')),
path('machine/', include('machine.urls')),
path('admin/',admin.site.urls),
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
我在 admin.py 中完成并解决了问题。
更改代码:
@admin.register(Module)
class ModuleAdmin(admin.ModelAdmin):
# fieldsets = (
# ('Information', {
# 'fields': ('name', 'model', 'serialNumber', 'slot')
# }),
# )
search_fields = ['name', 'model', 'serialNumber']
list_display = ('name', 'model', 'serialNumber', 'slot')
list_per_page = 15
这里我只是评论了那些字段集。所以它解决了这个问题。请给我解释一下这是怎么回事?
这里我没有使用任何管理模板。我正在使用默认的管理模板。我怎样才能扭转这个 url?
我得到的错误:
NoReverseMatch at /admin/machine/module/add/
Reverse for 'machine_module_change' with arguments '('',)' not found. 1 pattern(s) tried: ['admin/machine/module/(?P<object_id>.+)/change/$']
Request Method: POST
Request URL: http://localhost:8080/admin/machine/module/add/
Django Version: 3.0.8
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'machine_module_change' with arguments '('',)' not found. 1 pattern(s) tried: ['admin/machine/module/(?P<object_id>.+)/change/$']
Python Version: 3.7.7
Python Path:
['C:\Users\Administrator\Documents\CheckMeOut\checkmeout',
'C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python37.zip',
'C:\Users\Administrator\AppData\Local\Programs\Python\Python37\DLLs',
'C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib',
'C:\Users\Administrator\AppData\Local\Programs\Python\Python37',
'C:\Users\Administrator\AppData\Roaming\Python\Python37\site-packages',
'C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages',
'C:/Users/Administrator/Documents/CheckMeOut/checkmeout',
'C:/Users/Administrator/Documents/CheckMeOut/checkmeout/checkmeout']
Server time: Tue, 2 Mar 2021 15:21:42 +0530
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
from django.urls import reverse
urlpatterns = [
path('', include('main.urls')),
path('equipment/', include('equipment.urls')),
path('machine/', include('machine.urls')),
path('admin/',admin.site.urls),
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
我在 admin.py 中完成并解决了问题。
更改代码:
@admin.register(Module)
class ModuleAdmin(admin.ModelAdmin):
# fieldsets = (
# ('Information', {
# 'fields': ('name', 'model', 'serialNumber', 'slot')
# }),
# )
search_fields = ['name', 'model', 'serialNumber']
list_display = ('name', 'model', 'serialNumber', 'slot')
list_per_page = 15
这里我只是评论了那些字段集。所以它解决了这个问题。请给我解释一下这是怎么回事?