How to process reading and writing Json in Python involving Chinese characters

Source: Internet
Author: User
The following small series will provide you with a processing method for reading and writing Python Json that involves Chinese characters. I think this is quite good. now I will share it with you and give you a reference. Let's take a look at the small Editor. when preparing data for the front-end, we need to convert the data format to json format. To be honest, it is really tough to talk about Chinese characters, unless we know more about the Python encoding rules, otherwise, it would really hurt.

Entire logic

What we need to deal with is to process some articles, generate multiple html files, and then use json to display the article list, images, summaries, and titles.

Ideas

In order to expand data in the future, there must be a database. my idea is to write a simple webpage for submission input, post it to the background, and then input it to the database, write another page to display the article. after the display effect is correct, write a requests to dynamically crawl all the data to generate one html document. For the final json data, I only need to extract the data from the database to generate an achievement line.

Front end

In fact, the front-end is very simple. Recently, I have been writing web pages, so the front-end is done in minutes. The code is as follows:

Urls. pyfrom django. conf. urls import url, includefrom. import viewsurlpatterns = {url (r' ^ $ ', views. index, name = 'index'), url (r'add _ article/', views. add_article, name = 'add _ article'), url (r' ^ article /(? P
 
  
\ S +)/$ ', views. article, name = 'article'),} views. py # coding = utf-8from django. shortcuts import renderfrom. models import Tzxy # Create your views here. def index (request): return render (request, 'index.html ') def add_article (request): error = 'error' if request. method = 'Post': # obtain the content main_id = request in the previous request. POST ['main _ id'] img_url = request. POST ['IMG _ url'] title = request. POST ['title'] content = request. POST ['content'] abstract = content [: 50] print main_id indb = Tzxy (main_id = main_id, img_url = img_url, title = title, content = content, abstract = abstract) indb. save () error = 'success' return render (request, 'index.html ', {'error': error}) return render (request, 'index.html') def article (request, main_id ): article_detial = Tzxy. objects. get (main_id = main_id) return render (request, 'views.html ', {'content': article_detial}) models. pyfrom _ future _ import unicode_literalsfrom django. db import modelsfrom django. contrib import adminclass Tzxy (models. model): main_id = models. charField (max_length = 10) img_url = models. charField (max_length = 50, null = True) title = models. charField (max_length = 50) content = models. textField () abstract = models. charField (max_length = 200) admin. site. register (Tzxy)
 

I wrote a simple form for the template.

Index.html

  
   Title  
   

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.