分类目录归档:Python-Dev

[ django-admin外键字段自动生成的增删改查按钮去除 ]


隐藏 Django Admin 自动完成外键字段(如 leader_user)后面的四个按钮(编辑、添加、删除、查看)

admin.py

@admin.register(User)
class UserAdmin(auth_admin.UserAdmin):
    form = UserAdminChangeForm
    add_form = UserAdminCreationForm
    autocomplete_fields = ['leader_user']
    filter_horizontal = (
        "groups"

< Read more >

[ django 排序 ]


django的非外键排序

两张表我需要对part里面的字段进行排序, 但是没有外键关联

class Parts(models.Model):
    ...
    ...
    ...

class LocationDrawerComponentParts(models.Model):
    location_drawer_component = models.ForeignKey(
        "cews.LocationDrawerComponent", on_delete=models.CASCADE, null=False, blank=False
   

< Read more >

[ python编译安装 ]


二、解压 Python 安装包 1、Mac 双击自动解压。或在终端中执行命令解压 2、Linux (根据你所下载个Python3源码压缩包格式和名字选择对应命令解压缩,更多解压缩命令请具体查看Linux命令手册)

xz -d Python-3.10.1.tar.xz 1 或

tar xvf Python-3.10.1.tgz 1 或

tar -xf Python-3.10.1.tar 1 本文安装使用.tgz格式文件,故选用:tar xvf Python-3.10.1.tgz

三、释放编译文件 如果是root管理员账号登入安装,可以免除sudo命令,否则请务必使用sudo赋予最高执行权限:

c

< Read more >

[ UV包管理使用 ]


python uv包管理使用[https://docs.astral.sh/uv/getting-started/installation/#standalone-installer]

一. 直接使用官方推荐命令安装

curl -LsSf https://astral.sh/uv/install.sh | sh

二. 直接下载 文件

再把文件复制到这个目录下

root@iZf8zfb58x30ba21piywgxZ:/usr/local/bin# ls
uv  uvx

三. 使用

安装
uv python install 3.12
uv python install 3.11
uv 

< Read more >

[ django部署防止后台admin出现csrf ]


有时候后台admin登陆报错scrf, 就这样部署

(base) chf@chf:~/Nginx$ cat nginx-config/default.conf

# HTTP 强制跳转 HTTPS(前端)
server {
    listen 80;
    server_name frontend.chenhaifeng.top;
    return 301 https://$host$request_uri;
}

# HTTP 强制跳转 HTTPS(后端)
server {
    listen 80;
    server_name backend.chenhaifeng.top;

< Read more >

[ django自动事务源码解析 ]


1.启动django的时候

class WSGIHandler(base.BaseHandler):
    request_class = WSGIRequest

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.load_middleware() #加载中间件

1

2.发起请求的时候

一. 应该是WSGI服务-> 他调用了application(xxx,xxx)触发了call方法

import os

from django.core.as

< Read more >

[ django翻译功能 ]


django中使用多语言翻译

.
├── django_test
│   ├── asgi.py
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   ├── views.py
│   └── wsgi.py
├── locale
│   └── zh_Hans
│       └── LC_MESSAGES
│           ├── django.mo
│           └── django.po
└── manage.py

修改4个地方

USE_I18N
LANGUAGES
LOCALE_PATHS
MIDD

< Read more >