栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Django 基于jquery的ajax实现post请求

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Django 基于jquery的ajax实现post请求

Django 基于jquery的ajax实现post请求
  1. Django url.py
from django.contrib import admin
from django.urls import path
from apps.message import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('index/', views.index,name="index"),
    path('index/ajax/', views.index_ajax, name="index_ajax"),
]
  1. Django views,py
from django.http import HttpResponse
from django.shortcuts import render
from django.views.decorators.csrf import csrf_exempt
import json
# Create your views here.


@csrf_exempt
def index(request):
    if request.method == "POST":
        print("post")

    return render(request, 'index.html',)

@csrf_exempt
def index_ajax(request):
    if request.method == "POST":
        print("post",request.POST.get("username"),request.POST.get("password"))
    data = {'code': 200, 'msg': 'OK'}
    return HttpResponse(json.dumps(data))  # jq那边在 用js的反序列方法转换即可
  1. index.html


  
    
    ECharts
  

  
 
    

  
```

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/976647.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号