django:jquery中ajax的简单使用,另一个观点
对于文章django:jquery中ajax的简单使用,可以用一种方式分析。
创建django项目projectaa,创建应用appaa。
在urls窗口编写代码,projectaa/projectaa/urls:
from django.contrib import admin
from django.urls import path
from appaa import views
urlpatterns = [
path('admin/', admin.site.urls),
path('bb/', views.bb),
path('cal/', views.cal),
]
【django:jquery中ajax的简单使用,另一个观点】在views窗口编写代码,projectaa/appaa/views:
from django.shortcuts import HttpResponse, render
@csrf_exempt
def bb(request):
return render(request, 'bbbb.html')
@csrf_exempt
def cal(request):
aa = request.POST.get('input_a')
bb = request.POST.get('input_b')
cc = int(aa) + int(bb)
return HttpResponse(cc)
在template创建bbbb.html,并编写代码,projectaa/template/bbbb.html:
{% load staticfiles %}
Title - 锐客网
创建static文件夹。因为要使用jquery,所以要下载jquery的较新的版本,并放置在static文件夹中,此文中路径是,
projectaa/static/jquery-3.4.1.js。
在setting中设置static文件夹路径,在setting文件最下面增加以下代码,
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
在template/aaaa.html中增加以下代码,
{% load staticfiles %}
在浏览器中输入地址127.0.0.1:8000/bb/。
如果没有实现目的,尝试在terminal中运行命令
python manage.py makemigrations
python manage.py migrate
python manage.py runserver
推荐阅读
- 热闹中的孤独
- Shell-Bash变量与运算符
- JS中的各种宽高度定义及其应用
- 2021-02-17|2021-02-17 小儿按摩膻中穴-舒缓咳嗽
- 深入理解Go之generate
- 异地恋中,逐渐适应一个人到底意味着什么()
- 我眼中的佛系经纪人
- 《魔法科高中的劣等生》第26卷(Invasion篇)发售
- “成长”读书社群招募
- 2020-04-07vue中Axios的封装和API接口的管理