且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取最后一个插入ID

更新时间:2022-12-12 15:16:41

我想你把保存文件的视图写入db?

I guess you wrote the view like save file into db ?

那么这里是答案将帮助你最后插入 id 在html页面

then here is the answer will help you to get last inserted id in html page

首先写两个视图(请求)。

First write two view(request).


  1. 用于呈现页面模板和上下文。

  2. 第二个视图是其中文件处理并获取 id

  1. For rendering page template and context.
  2. Second view is for where file handling and get the id

like:

def view_second(request)
        if request.method == 'POST':
            if form valid:
                #get file here
                new.save()
                msg = new.id
            return HttpResponse(msg)

就是这样,现在在你的html之后的dropzone脚本..

And that's it, Now in your html after the dropzone script ..

Dropzone.options.myDropzone = {
  init: function() {
    this.on("success", function(file, response) {
      #alert(response)  
    });

所以在回复中你会得到 id

so in the response you will get the id