小编M1n*_*zwy的帖子

DRF中的has_object_permission和has_permission之间有什么区别:权限?

我对BasePermissionDjango-rest框架感到困惑.

在这里我定义了一个类:IsAuthenticatedAndOwner.

class IsAuthenticatedAndOwner(BasePermission):
    message = 'You must be the owner of this object.'
    def has_permission(self, request, view):
        print('called')
        return False
    def has_object_permission(self, request, view, obj):
        # return obj.user == request.user
        return False
Run Code Online (Sandbox Code Playgroud)

在...中使用 views.py

class StudentUpdateAPIView(RetrieveUpdateAPIView):
    serializer_class = StudentCreateUpdateSerializer
    queryset = Student.objects.all()
    lookup_field = 'pk'
    permissions_classes = [IsAuthenticatedAndOwner]
Run Code Online (Sandbox Code Playgroud)

但它根本不起作用.每个人都可以传递权限并更新数据.在called未打印.


我曾经定义过这个类: IsNotAuthenticated

class IsNotAuthenticated(BasePermission):
    message = 'You are already logged in.'
    def has_permission(self, request, view):
        return not request.user.is_authenticated()
Run Code Online (Sandbox Code Playgroud)

它在该功能中运行良好

class UserCreateAPIView(CreateAPIView):
    serializer_class = UserCreateSerializer …
Run Code Online (Sandbox Code Playgroud)

python django django-rest-framework

10
推荐指数
2
解决办法
4919
查看次数

使用psycopg2的PostgreSQL拒绝连接

psycopg2.OperationalError:无法连接到服务器:连接被拒绝

服务器是否在主机“ 45.32.1XX.2XX”上运行并在端口5432上接受TCP / IP连接?

在这里,我打开了我的插座。

tcp        0      0 127.0.0.1:5432          0.0.0.0:*  LISTEN      11516/postgres                
tcp6       0      0 ::1:5432                :::*       LISTEN      11516/postgres
Run Code Online (Sandbox Code Playgroud)

我用谷歌搜索应该对此进行修改pg_hba.conf?但是在我的postgresql根文件中,我根本找不到该文件。

另外,我已经成功连接了另一台服务器。

谢谢。

在这里,我修改了pg_hba.conf,对其进行了更新host all all 218.3.A.B trust并重新加载。但是它也不起作用。

python postgresql python-3.x

5
推荐指数
2
解决办法
1万
查看次数

找不到 Django 图像 src

\project_structure
-app
\project
  -settings.py
  -...
\picture
  -panda.jpg
Run Code Online (Sandbox Code Playgroud)

我已将图片上传到picture.

class Goods(models.Model):
    pic = models.ImageField(upload_to='picture')
Run Code Online (Sandbox Code Playgroud)

里面的数据databasepicture/panda.jpg

现在,我如何在 html 中显示它?

我用html写了这个:

<p>{{each.pic}}</p>
<img src='{{ each.pic.url }}' />
Run Code Online (Sandbox Code Playgroud)

浏览器中的源代码是这样的:

picture/panda.jpg
<img src='picture/panda.jpg' />
Run Code Online (Sandbox Code Playgroud)

图像链接到http://localhost:8000/my_sell/picture/panda.jpg。并且无法显示。

我怎样才能解决这个问题,我已经试过加载media_rootsettings.py无用。

python django

5
推荐指数
1
解决办法
1万
查看次数