django运行配置

Setting.py

python 复制代码
# Internationalization
# https://docs.djangoproject.com/en/5.0/topics/i18n/

# 较早版本的 Django 可以尝试改为'zh-CN',具体可查看
# "python/site-packages/django/conf/locale/"中的语言名称
LANGUAGE_CODE = 'zh-Hans'

# Windows环境中此项的时区必须和系统一致,设置为 Asia/Shanghai。
# 另外此项设置如果保持 UTC 有可能导致 Django 时间和本地时间不同的情况。
TIME_ZONE = 'Asia/Shanghai'

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/
import os
STATIC_URL = "static/"
STATIC_ROOT = os.path.join(os.path.dirname(__file__),'static')
STATICFILES_DIRS=[
    os.path.join(BASE_DIR,'static'),
    os.path.join(BASE_DIR, "static/images"),
    ("jpg", os.path.join(STATIC_ROOT, "images").replace("\\", "/")),


]

# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
SIMPLEUI_HOME_INFO=False
SIMPLEUI_ANALYSIS=False


from django.conf.locale.zh_Hans import formats as zh_formats


DATETIME_FORMAT = "Y-m-d H:i:s"
zh_formats.DATETIME_FORMAT = "Y年m月d日 H:i:s"


# settings.py

# 设置文件编码
FILE_CHARSET = 'utf-8'

# 设置默认编码
DEFAULT_CHARSET = 'utf-8'

# 设置响应编码
DEFAULT_CONTENT_TYPE = 'text/html; charset=utf-8'

LOGIN_URL = '/login/'  # 这里是默认的登录页面的 URL

<my_app>/apps.py

python 复制代码
from django.apps import AppConfig


class ShoppingConfig(AppConfig):
    default_auto_field = "django.db.models.BigAutoField"
    name = "shopping"
    verbose_name = "管理"

<my_app>/urls.py

python 复制代码
from django.urls import path
from . import views

app_name = "app_name"

urlpatterns = [
    path("", views.index, name="index"),
]

<my_app>/views.py 类视图

python 复制代码
from django.views import View
from django.utils.decorators import method_decorator


class MyView(View):
    @method_decorator(login_require)  # 给该视图下所有的请求都加上登录校验
    def dispatch(self, request, *args, **kwargs):
        return super().dispatch(request, *args, **kwargs)

    def get(self, request):
		pass

    def post(self, request):
		pass

在 <my_app>/urls.py 中添加

python 复制代码
from django.urls import path
from . import views

app_name = "app_name"

urlpatterns = [
    path("", views.index, name="index"),
    path("my_view/", views.MyView.as_view(), name="my_view"),
]

类视图使用完成.

js 发送get 请求

可以使用 window.open(url) 在前端的 js 中实现快速get 请求, 而不是使用 ajax.get()