Python connects to SQLite database and Django gets receive HTML data

Source: Internet
Author: User
Tags sqlite sqlite database


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)) # string insert string sql
    sql = ‘‘ ‘‘ insert into ‘comment_comment’ (txt, ‘footer’) values (\ "% s \", \ "% s \"); ‘‘ ‘% (txt, footer) # string insert string sql
    try:
        cu.execute (sql)
        cx.commit ()
    except Exception as e:
        with open ("D: \ Python-Test \ StuProject \ dblog.txt", ‘a +‘) as f:
            log = ‘‘ ‘Error executing SQL:% s \ n Output:% s’ ‘% (e, sql)
            # f.write (log)
        pass
    print (cu)

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

cur_page = 1
def net163 (request):
    global cur_page # Handle error local variable ‘cur_page1’ referenced before assignment
    try:
        #cur_page = int (request.GET.get (‘cur_page’, ‘1‘)) # Jump page number
        if request.POST:
            cur_page = int (request.POST [‘num‘])
        elif request.GET:
            cur_page = int (request.GET [‘cur_page’])
        else:
            print ("Data transmission error")
    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, # Number of pages displayed
            show_page_item_len = 10) #Number of pages
    return render (request, ‘Net163.html’, {‘pagination’: pagination}) 




Python connects to SQLite database and Django gets receive HTML data


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.