Python連接Sqlite數據庫及Django獲取接收Html數據


def sqlitetest(txt,footer):
    cx = sqlite3.connect("D:\Python-Test\StuProject\db.sqlite3")
    cu = cx.cursor()
    #sql = '''insert into 'comment_comment'(txt,'footer') values (\"%s\",\"%s\");'''%(pymysql.escape_string(txt),pymysql.escape_string(footer))#字符串插入字符串sql
    sql = '''insert into 'comment_comment'(txt,'footer') values (\"%s\",\"%s\");''' % (txt, footer)  # 字符串插入字符串sql
    try:
        cu.execute(sql)
        cx.commit()
    except Exception as e:
        with open("D:\Python-Test\StuProject\dblog.txt",'a+') as f:
            log = '''執行sql發生錯誤:%s \n 輸出:%s'''%(e,sql)
            #f.write(log)
        pass
    print(cu)

++++++++++++++++++++++++++++++++++++++++++++++++++++

cur_page = 1
def net163(request):
    global cur_page#處理報錯local variable 'cur_page1' referenced before assignment
    try:
        #cur_page = int(request.GET.get('cur_page', '1'))#跳轉頁碼
        if request.POST:
            cur_page = int(request.POST['num'])
        elif request.GET:
            cur_page = int(request.GET['cur_page'])
        else:
            print("數據傳輸有誤")
    except ValueError:
        cur_page = 1
    pagination = Pagination.create_pagination(
            from_name='comment.models',
            model_name='comment',
            cur_page=cur_page,
            start_page_omit_symbol='...',
            end_page_omit_symbol='...',
            one_page_data_size=30,#每頁顯示數目
            show_page_item_len=10)#分頁數目
    return render(request, 'Net163.html', {'pagination': pagination})

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM