[英]Debug from Django admin
I'm trying to have a print statement appear on the console every time I add data into my Postgres Database (For example "Post succeeded") from the Django admin but no matter where I put print statements (in admin.py or the models) nothing is appearing. 每次我从Django管理员添加数据到我的Postgres数据库(例如“Post succeeded”)时,我都试图在控制台上出现一个print语句,但无论我在哪里放置print语句(在admin.py或模型中)没有任何东西出现。 I know the data is going through as there is a POST statement that goes through
我知道数据正在通过,因为有一个POST语句通过
and the data is in the database. 并且数据在数据库中。
In your Admin object, you can put a print
statement in the save_model()
method. 在Admin对象中,可以在
save_model()
方法中放置print
语句。 It sounds like that's where it will best suit you if you want to print something after adding data. 如果你想在添加数据后打印一些东西,听起来就是最适合你的地方。
It would look something like this: 它看起来像这样:
class FooAdmin(admin.ModelAdmin):
...
class Meta:
model = Foo
def save_model(self, request, obj, form, change):
print('Post succeeded')
obj.save()
admin.site.register(Foo, FooAdmin)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.