模型未显示在 django admin 中

发布于 2024-09-05 01:05:07 字数 2169 浏览 1 评论 0原文

为了自己的乐趣,我已经创建了几个 django 应用程序和东西,到目前为止一切都工作正常。

现在我刚刚创建了新项目(django 1.2.1),从一开始就遇到了麻烦。

我创建了新的应用程序 - 游戏和新模型游戏。我创建了admin.py并将相关内容放入其中。跑syncdb并去检查管理员。模型没有出现在那里。

我继续检查并仔细检查并阅读以前的类似线程: 注册模型不会显示在管理中 Django 应用程序未显示在管理界面中

我看得出来,他们也帮不了我。也许其他人可以为我指出这一点。

游戏应用程序中的 models.py:

# -*- coding: utf-8 -*-
from django.db import models

class Game(models.Model):
      type = models.IntegerField(blank=False, null=False, default=1)
      teamone = models.CharField(max_length=100, blank=False, null=False)
      teamtwo = models.CharField(max_length=100, blank=False, null=False)
      gametime = models.DateTimeField(blank=False, null=False)

游戏应用程序中的 admin.py:

# -*- coding: utf-8 -*-
from jalka.game.models import Game
from django.contrib import admin

class GameAdmin(admin.ModelAdmin):
      list_display    = ['type', 'teamone', 'teamtwo', 'gametime']
      
admin.site.register(Game, GameAdmin)

项目 settings.py:

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'jalka.urls'

TEMPLATE_DIRS = (
      "/home/projects/jalka/templates/"
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'game',
)

urls.py:

from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
      # Example:
      # (r'^jalka/', include('jalka.foo.urls')),
      (r'^admin/', include(admin.site.urls)),
)

I have ceated several django apps and stuffs for my own fun and so far everything has been working fine.

Now I just created new project (django 1.2.1) and have run into trouble from 1st moments.

I created new app - game and new model Game. I created admin.py and put related stuff into it. Ran syncdb and went to check into admin. Model did not show up there.

I proceeded to check and doublecheck and read through previous similar threads:
Registered models do not show up in admin
Django App Not Showing up in Admin Interface

But as far as I can tell, they don't help me either. Perhaps someone else can point this out for me.

models.py in game app:

# -*- coding: utf-8 -*-
from django.db import models

class Game(models.Model):
      type = models.IntegerField(blank=False, null=False, default=1)
      teamone = models.CharField(max_length=100, blank=False, null=False)
      teamtwo = models.CharField(max_length=100, blank=False, null=False)
      gametime = models.DateTimeField(blank=False, null=False)

admin.py in game app:

# -*- coding: utf-8 -*-
from jalka.game.models import Game
from django.contrib import admin

class GameAdmin(admin.ModelAdmin):
      list_display    = ['type', 'teamone', 'teamtwo', 'gametime']
      
admin.site.register(Game, GameAdmin)

project settings.py:

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'jalka.urls'

TEMPLATE_DIRS = (
      "/home/projects/jalka/templates/"
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'game',
)

urls.py:

from django.conf.urls.defaults import *

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
      # Example:
      # (r'^jalka/', include('jalka.foo.urls')),
      (r'^admin/', include(admin.site.urls)),
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

飘落散花 2024-09-12 01:05:07

报告的问题可能是因为您跳过了为管理站点注册模型。这可以通过在您的应用程序下创建一个 admin.py 文件来完成,然后使用以下命令注册模型:

from django.contrib import admin
from .models import MyModel

admin.site.register(MyModel)

The problem reported can be because you skipped registering the models for the admin site. This can be done, creating an admin.py file under your app, and there registering the models with:

from django.contrib import admin
from .models import MyModel

admin.site.register(MyModel)
忆依然 2024-09-12 01:05:07

嗯...尝试在 settings.py 中更改您的应用程序的包含内容:

发件人:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'game',
    ....

收件人:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'YOUR_PROJECT.game',# OR 'YOUR_PROJECT.Game'

Hmmmm...Try change include of your app in settings.py:

From:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'game',
    ....

To:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'YOUR_PROJECT.game',# OR 'YOUR_PROJECT.Game'
左耳近心 2024-09-12 01:05:07

Django 2.0 也有同样的问题。

以下代码不起作用:

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin

from users import models

admin.register(models.User, UserAdmin)

事实证明该行

admin.register(models.User, UserAdmin)

应该是

admin.site.register(models.User, UserAdmin)

因为我没有收到任何警告,只是想在这里指出这一点。

Had the same issue with Django 2.0.

The following code didn't work:

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin

from users import models

admin.register(models.User, UserAdmin)

It turns out the line

admin.register(models.User, UserAdmin)

should have been

admin.site.register(models.User, UserAdmin)

Since I didn't get any warnings, just wanted to point out this thing here too.

同尘 2024-09-12 01:05:07

我知道这已经得到回答和接受,但我想分享我对这个问题的解决方案,也许它会帮助其他人。

我的 INSTALLED_APPS 看起来像这样:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'core',  # <---- this is my custom app
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    'south',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)

看,我把我的应用程序放在 Django 的管理应用程序之前,显然它按这个顺序加载它们。我只是将我的应用程序移至管理员下方,它就开始显示:)

I know this has already been answered and accepted, but I felt like sharing what my solution to this problem was, maybe it will help someone else.

My INSTALLED_APPS looked like this:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'core',  # <---- this is my custom app
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    'south',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)

See, I put my app before Django's admin app, and apparently it loads them in that order. I simply moved my app right below the admin, and it started showing up :)

久隐师 2024-09-12 01:05:07

我有同样的问题。一切都做对了。但我没有查看模型的权限。

只需授予所需的权限(查看/添加/编辑/等),然后再次检查。

使用管理面板授予权限:

  1. 使用您的超级用户帐户的凭据登录到站点。
  2. 管理站点的顶层显示所有模型,按“Django 应用程序”排序。在“身份验证和授权”部分中,您可以单击“用户”或“组”链接以查看其现有记录。
  3. 选择并添加所需的权限

选择并添加所需的权限
输入图像描述这里

参考通过管理面板添加/更改权限

替代方案:
使用代码
参考 Django 官方文档

I had the same issue. Done everything right. But I didn't have permission to view the model.

Just give the required permission (view/add/edit/etc) and then check again.

Give Permission using admin panel:

  1. Login to the site using the credentials for your superuser account.
  2. The top level of the Admin site displays all of your models, sorted by "Django application". From the Authentication and Authorization section, you can click the Users or Groups links to see their existing records.
  3. Select and add the required permission

Select and add the required permission
enter image description here

refer this to add/change permission through the admin panel

Alternative:
Using code
refer Official Django Doc

素染倾城色 2024-09-12 01:05:07

对于 Django 1.10 帮助我按照最后使用 (admin.ModelAdmin) 的方式注册模型

from django.contrib import admin

from .models import YourModel
admin.register(YourModel)(admin.ModelAdmin)

For Django 1.10 helped to me to register the Model following way with (admin.ModelAdmin) at the end

from django.contrib import admin

from .models import YourModel
admin.register(YourModel)(admin.ModelAdmin)
客…行舟 2024-09-12 01:05:07

这可能非常罕见,但我今天遇到了一个问题,我创建的 admin.py 文件的权限已损坏,因此 django 无法读取它。我删除了该文件并重新创建它,成功了。

希望这可以拯救某人,如果他们遇到我的问题。

It's probably very rare but I had an issue today where the permissions on the admin.py file I had created were corrupt and thus made it unreadable by django. I deleted the file and recreated it with success.

Hope that saves someone, should they stumble here with my problem.

辞别 2024-09-12 01:05:07

我也很难注册我的模型(尝试了上面的所有建议),直到我做了一件非常简单的事情。我将 admin.py 从目录移至项目目录 - 刷新管理屏幕并将其移回,瞧,进入模型应用程序目录 - 它们都立即出现。我正在使用 PyCharm 所以不确定这是否导致了一些问题。

我的设置正是 Django 手册所说的 -

models.py

class xxx(models.Model):
    ....
    def __str__(self):  # __str__ for Python 3, __unicode__ for Python 2
        return self.name

admin.py

from .models import xxx
admin.site.register(xxx)

I struggled with registering my models (tried all the suggestions above) too until I did a very simple thing. I moved my admin.py out of the directory up to the project directory - refreshed the admin screen and moved it back and voila into the models app directory - they all appeared instantly. I'm using PyCharm so not sure if that was causing some problems.

My setup is exactly what the Django manual says -

models.py

class xxx(models.Model):
    ....
    def __str__(self):  # __str__ for Python 3, __unicode__ for Python 2
        return self.name

admin.py

from .models import xxx
admin.site.register(xxx)
南街女流氓 2024-09-12 01:05:07

我正在使用数字海洋,也遇到了这个问题。解决方案是重新启动服务。我使用了

服务gunicorn restart

,模型就显示出来了

I am using digital ocean and also ran into this issue. The solution was a service restart. I used

service gunicorn restart

and that got the model to show up

小矜持 2024-09-12 01:05:07

我只需要重新启动 apache 服务即可。服务 apache2 重新启动。然后新的模型出现了。

I just had to restart apache service. service apache2 restart. Then new models shown up.

沉睡月亮 2024-09-12 01:05:07

我有同样的问题。我的几个模型没有显示在 django admin dashbaord 中,因为我没有在 admin.py 文件中注册这些模型。

//Import all the models if you have many

from store.models import *

admin.site.register(Order)
admin.site.register(OrderItem)

这为我解决了这个问题。只需注册并刷新您的网页,模型就会在管理仪表板中可见

I had the same issue. Few of my models were not showing in the django admin dashbaord because I had not registered those models in my admin.py file.

//Import all the models if you have many

from store.models import *

admin.site.register(Order)
admin.site.register(OrderItem)

This fixed it for me. Just register and refresh your webpage and the models will be visible in the admin dashboard

冷夜 2024-09-12 01:05:07

我有同样的问题。我解决了这个问题,将 admin 寄存器添加到 admin.py 中。
而且我不需要添加额外的课程。

喜欢:

from jalka.game.models import Game
from django.contrib import admin

admin.site.register(Game)

环境:Win10、Django 1.8

I have the same problem. I solve this to add register of admin to admin.py.
And I don't need to add extra class.

Like:

from jalka.game.models import Game
from django.contrib import admin

admin.site.register(Game)

Enviroment: Win10、Django 1.8

与他有关 2024-09-12 01:05:07

我有同样的问题,我解决如下
首先转到您的 app.py 文件并复制类名。

from django.apps import AppConfig

class **ResumeConfig**(AppConfig):
name = 'resume'

现在转到setting.py并将其放置在应用程序定义中,如下所示:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
**'resume.apps.ResumeConfig'**
]

在终端中保存并运行命令

python manage.py makemigrations
python manage.py migrate

运行服务器并转到/admin
你的问题将会得到解决

I had the same issue and i resolved it as follow
first go to your app.py file and copy the class name.

from django.apps import AppConfig

class **ResumeConfig**(AppConfig):
name = 'resume'

now go to setting.py and place it in application definition as follow:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
**'resume.apps.ResumeConfig'**
]

save and run the commands in the terminal

python manage.py makemigrations
python manage.py migrate

run your server and go to /admin
your problem will be solved

护你周全 2024-09-12 01:05:07

你只需要注册你的模型。
到同一应用程序的 admin.py 文件并写入,

from .models import "Modelname"

admin.site.register(("Modelname")) 
#create tuple to register more than one model

you just need to register your model.
got to admin.py file of the same app and write,

from .models import "Modelname"

admin.site.register(("Modelname")) 
#create tuple to register more than one model
凶凌 2024-09-12 01:05:07

我还想补充一点,我做了这些答案所说的一切,除了我没有在命令行上输入 sudo service apache2 restart 以使更改生效。 (因为我正在亚马逊网络服务的端口 80 上的实时服务器上进行测试。我还使用 Ubuntu 操作系统。)这为我解决了这个问题。我希望这可以帮助某人。

I would also like to add, that I did everything these answers said, except I did not enter on the command line sudo service apache2 restart which I needed to make the changes take effect. (Because I was testing on a live server on port 80 on amazon web services. I was also using an Ubuntu operating system.) That solved it for me. I hope this might help somebody.

ぶ宁プ宁ぶ 2024-09-12 01:05:07

我遇到了同样的问题,
重新启动后,我的开发服务器模型显示在管理页面中。

I got the same issue,
After restart my development server model is showing in admin page.

浮华 2024-09-12 01:05:07

将您的管理代码更改为:

from django.contrib import admin
from .models import Game

class GameAdmin(admin.ModelAdmin):
  list_display    = ['type', 'teamone', 'teamtwo', 'gametime']

admin.site.register(Game, GameAdmin)

还要确保该应用程序包含在 settings.py 文件中,并确保为您的模型导入正确的名称。导致此问题的另一个原因是在模型字段末尾放置一个逗号 (,) ,就好像它是一个 Python 列表一样。

Change your admin code to this:

from django.contrib import admin
from .models import Game

class GameAdmin(admin.ModelAdmin):
  list_display    = ['type', 'teamone', 'teamtwo', 'gametime']

admin.site.register(Game, GameAdmin)

Also make sure the app is included in settings.py file and make sure you're importing the right name for your model. Another reason that can bring about this issue is putting a comma (,) at the end of your model fields as though it a python list.

慕烟庭风 2024-09-12 01:05:07

由于我使用 ADMIN_REORDER(https://pypi. org/project/django-modeladmin-reorder/)在settings.py中控制模型顺序,不久前添加并忘记了。将新模型添加到settings.py并显示出来。

My new model not showing up on Admin page due to me using ADMIN_REORDER(https://pypi.org/project/django-modeladmin-reorder/) in settings.py to control model order, added a while back and forgotten. Added the new model to settings.py and it shows up.

红ご颜醉 2024-09-12 01:05:07

添加到 Saff 所说的内容中,您的 settings.py 应该如下所示:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'YOUR_PROJECT',
    # And
    'YOUR_PROJECT.Foo',
    'YOUR_PROJECT.Bar',
)

Adding to what Saff said, your settings.py should be like this:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'YOUR_PROJECT',
    # And
    'YOUR_PROJECT.Foo',
    'YOUR_PROJECT.Bar',
)
思念绕指尖 2024-09-12 01:05:07

错误可能是在你的“def”中的views.py,你应该检查你是否得到了

If mymodel.is_valid():
mymodel = model.save()

我会给你一小部分我的代码,这样你就会明白

@login_required(login_url='/home/')
def ask_question(request):
user_asking = UserAsking()

if request.method == "POST":
    user_asking = UserAsking(request.POST)

    if user_asking.is_valid():
        user_asking.save()

    return redirect(home)

return render(request, 'app/ask_question.html', {
    'user_asking': user_asking,
})

“UserAsking是一种形式”。
我希望我确实帮助了你

The mistake might be at views.pyin your "def" you should check if you got

If mymodel.is_valid():
mymodel = model.save()

I will give you a piee of my code so you would understand it

@login_required(login_url='/home/')
def ask_question(request):
user_asking = UserAsking()

if request.method == "POST":
    user_asking = UserAsking(request.POST)

    if user_asking.is_valid():
        user_asking.save()

    return redirect(home)

return render(request, 'app/ask_question.html', {
    'user_asking': user_asking,
})

`UserAsking is a form.
i hope i did help you

宛菡 2024-09-12 01:05:07

可能的原因之一是您没有关闭旧的 python 进程。

One of the possible reasons is that you do not close old python processes.

酒浓于脸红 2024-09-12 01:05:07

我在安装在 docker 容器中的 django 实例上遇到了类似的问题。代码是正确的,但对 admin.py 的更改没有出现在 django admin 中。

退出 django 进程并使用 docker-compose up 重新挂载容器后,添加的模型在 django admin 中可用。

I had a similar issue on an instance of django mounted in a docker container. The code was correct but changes to admin.py were not appearing in django admin.

After quitting the django process and remounting the container with docker-compose up, the added models became available in django admin.

執念 2024-09-12 01:05:07

我将所有管理类放在一个文件夹 ./sites/ 中,该文件夹仅因我的循环依赖而起作用。我修好了它们,其他一切都停止工作了。

当我将该目录从 ./sites/ 重命名为 ./admin/ 时,它起作用了。

I had all my Admin classes in a folder ./sites/ which only worked because of cercular dependencies I had. I fixed them, and everything else stopped working.

When I renamed that directory from ./sites/ to ./admin/ it worked.

执着的年纪 2024-09-12 01:05:07

另一件需要指出的事情是,您应该确保您是使用超级用户登录的。

可能是您登录的用户对查看容量的权限有限,因此请尝试这样做。

我在 Django 2.0 中仍然仅使用应用程序的名称(即“游戏”)来注册我的应用程序。但问题出在登录用户权限上。

Another thing to point out is that you should make sure you're signed in with a superuser.

It could be that you are signed in with a user who has limited permission on view capacity so try that.

I in Django 2.0 I still register my app using just the name of the app i.e 'game'. But the issue was in the logged in user permissions.

度的依靠╰つ 2024-09-12 01:05:07

我正在使用本地代码更新远程服务器,但远程服务器仍在管理屏幕中使用旧模型。我的本地服务器和远程服务器之间的一切看起来都完全相同 - 数据库表匹配并且代码也相同。

问题原来是远程服务器正在使用 venv 环境运行。运行 source venv/bin/activate 并进行迁移后,管理员显示了所有新模型。

I was updating a remote server with code from local, but the remote server was still using the old models in the admin screen. Everything looked exactly the same between my local and the remote server - the database tables matched and the code was also identical.

The problem turned out the remote server was running using the venv environment. After running source venv/bin/activate and then doing the migrations, the admin showed all the new models.

不回头走下去 2024-09-12 01:05:07

如果您有多个模型要注册,请使用。

admin.site.register((Model1 , Model2 , Model3))

admin.site.register([Model1 , Model2 , Model3])

admin.py 文件中的

If you have multiple models to register then use.

admin.site.register((Model1 , Model2 , Model3))

or

admin.site.register([Model1 , Model2 , Model3])

in your admin.py file.

究竟谁懂我的在乎 2024-09-12 01:05:07

我有同样的错误,但我没有在 INSALLED_APPS 中提及我的应用程序

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'myapp.apps.myappConfig',
)

我已经注册了该模型,但忘记在 INSTALLED_APPS 中提及我的应用程序,在提及它对我有用后

I have the same error but I have not mentioned my app in INSALLED_APPS

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'myapp.apps.myappConfig',
)

I have already registered the model but forgot to mention my app in INSTALLED_APPS and after mentioning it works for me

寄人书 2024-09-12 01:05:07

对我来说,移民是一个问题。如果您创建了这个新应用,请尝试执行以下操作:

python manage.py makemigrations <name_of_your_app>
python manage.py migrate <name_of_your_app>

您不需要将所有 admin.site.register 包含在单个应用中,您可以在 admin 的相应应用中指定它们.py 文件。

For me, migration was an issue. If you created this new app, try doing the following:

python manage.py makemigrations <name_of_your_app>
python manage.py migrate <name_of_your_app>

You do not need to include all admin.site.register in a single app, you could specify them in their corresponding app at the admin.py file.

迷离° 2024-09-12 01:05:07

我遇到了同样的问题,django=4.0docker-compose 我没有使用 ModelAdmin,结果在一次调用中注册了多个模型 <运行迁移时 code>admin.site.register 出错。

所以这样做

admin.site.register(ModelA, ModelB)

并没有成功。相反,你做了类似的事情,

admin.site.register(ModelA)
admin.site.register(ModelB)

我希望它可以帮助任何人 dockerizing 他们的 Django 应用程序

I had this same issue, django=4.0 with docker-compose i was not using ModelAdmin, turns out registering multiple Models in one call to admin.site.register errors out when running migration.

So doing

admin.site.register(ModelA, ModelB)

did not work. instead, you I did something like

admin.site.register(ModelA)
admin.site.register(ModelB)

I hope it helps anyone dockerizing their Django App

萌能量女王 2024-09-12 01:05:07

通过管理面板中的编辑用户功能为您的用户授予“超级用户身份”

输入图片此处描述

您登录的用户很可能不是超级用户,并且不具备新创建模型所需的权限

在Django中,创建并迁移新模型后,现有用户的权限不会更新。默认情况下,只有具有超级用户状态的用户才能查看、添加、更改和删除这些模型的记录。

为了解决该问题并避免将来再次出现该问题,请为您的开发用户提供“超级用户身份”。

Give your user "Superuser status" through the edit user functionality in the admin panel.

enter image description here

Most probably the user you are signed in is not a superuser and doesn't have the required permissions for the newly created models.

In Django, after new models are created and migrated, the permissions of the existing users are not updated. Only the users with Superuser status can by default view, add, change and delete records for these models.

To fix the problem and avoid it in the future give "Superuser status" to your development user.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文