我已经在Django视图中设置了一个函数,该函数从API请求数据,然后通过单击按钮将其保存到数据库中,但是数据格式存在问题。
目标非常简单:从产品说明中删除所有html代码。
以下是说明的当前格式的示例:
node_modules/babel-loader
预期结果应如下所示(删除所有
<ul>\n <li>\n <p>Based on the legendary Roald Dahl’s classic children’s book of the same name, “Matilda! The Musical” is all about little Matilda Wormwood, an extremely smart and bright girl whose genius is unfortunately, unrecognized by her dull parents.</p></li>\n <li>\n <p>Meet other characters you will love to hate such as the wicked Mrs. Trunchbull, her evil headmistress and meet Miss Honey, the only one who understands love Matilda with her sharp mind and vivid imagination</p></li>\n <li>\n <p>\"Once in a blue moon, a show comes out blazing and restores your faith in Broadway. 'Matilda The Musical' is that show\" <strong>-Elisabeth Vincentelli, NEW YORK POST</strong></p></li>\n <li>\n <p>Winner of <strong>5 Tony Awards</strong> and <strong>7 Olivier Awards</strong></p></li>\n</ul>\n<p><strong>FAQ's</strong></p>\n<p>1) <strong>Is there a possibility that I will get partial view seating with my Matilda tickets?</strong></p>\n<p>No, you will only receive full view seats. Although, there are a few seats in the Balcony section that have a thin structural pipe within eyesight. This, however, will not hamper your view or affect your show experience.</p>\n<p>2) <strong>Is there a dress code for Matilda The Musical?</strong></p>\n<p>Smart casual is recommended for Matilda The Musical. Keep in mind the theater is air conditioned throughout the year and can get a bit chilly. </p>\n<p>3) <strong>Is there a minimum age requirement to watch Matilda The Musical?</strong></p>\n<p>All guests require a ticket, regardless of age (for which there is no minimum requirement). We recommend children be at least 6 years of age to attend a performance of Matilda.</p>\n<p>4) <strong>Is the ticket price for children different than adults?</strong></p>\n<p>No, children will have to purchase a full priced ticket.</p>\n<p>5) <strong>Does the Shubert Theater have wheelchair accessible seating?</strong></p>\n<p>Wheelchair accessible seating is available at the Shubert Theater; however, seats are subject to availability. </p>\n<p>6) <strong>What is Matilda The Musical's duration and will there be an intermission?</strong></p>\n<p>The show runs for 2 hours and 30 minutes, with one intermission. </p>\n<p>7) <strong>Can we bring outside food into the Shubert Theater?</strong></p>\n<p>Food and beverages from outside are strictly prohibited.</p>\n<p>8) <strong>Can I can bring a bag, luggage, camera etc.?</strong> </p>\n<p>No large pieces of luggage are allowed inside, but you can check them in at the Secure Baggage Area, located near the entrance. Handbags, cameras, and other small accessories are allowed inside. If carrying a camera, be sure to keep it in your bag at all times. Photography is strictly prohibited inside the theater. </p>\n<p>9) <strong>When should I arrive at the theater?</strong></p>\n<p>We recommend reaching the theater 30 minutes before curtain time. Performances begin promptly at the time stated on your ticket and the theater reserves the right to deny entry if you are late. </p>\n<p>10) <strong>Will my Matilda The Musical seats be together?</strong></p>\n<p>Yes, we always make sure your reservation seats are together. Keep in mind, many theaters use an odd and even-numbered sequence for seating. </p>
这是我从Django视图中获得的Def:
Based on the legendary children's book by the legendary Roald Dahl, "Matilda! "The musical" is about little Matilda Wormwood, an extremely intelligent and brilliant girl whose genius is unfortunately not recognized by her dull parents. Darling, the only person who understands Matilda's love with her lively mind and overflowing imagination. "Once in a blue moon, a show ignites and restores your confidence in Broadway." NEW YORK POST Winner of 5 Tony Awards and 7 Olivier Awards Faq 1) Can I get a partial view with my Matilda tickets? No, you will only receive tickets with a full view. Although some seats in the Balcony section have a thin structural pipe within sight. This, however, will not interfere with your vision or affect your entertainment experience. 2) Is there a dress code for Matilda The Musical? Relaxed chic is recommended for Matilda The Musical. Keep in mind that the theatre is air-conditioned all year round and may be a little cold. 3) Is there a minimum age to watch Matilda The Musical? All customers need a ticket, regardless of their age (for which there is no minimum requirement). We recommend that children be at least 6 years old to attend a Matilda performance. 4) Is the price of the ticket for children different from that of adults? No, the children will have to buy a full fare ticket. 5) Does the Shubert Theatre have wheelchair accessible seats? Wheelchair accessible seats are available at the Shubert Theatre; however, seats are subject to availability. 6) How long is Matilda The Musical and will there be an intermission? The show lasts 2 hours and 30 minutes, with an intermission. 7) Can we bring food from outside in the Shubert Theatre? Food and drinks from outside are strictly forbidden. 8) Can I bring a bag, luggage, camera, etc.?
还有我的Django模型:
def api_data(request):
if request.GET.get('mybtn'):
resp_1 = requests.get(
"https://www.headout.com/api/public/v1/product/listing/list-by/city?language=en&cityCode=PARIS&limit=5000¤cyCode=CAD",
headers={
"Headout-Auth": HEADOUT_TEST_API_KEY
})
resp_1_data = resp_1.json()
base_url_2 = "https://www.test-headout.com/api/public/v1/product/get/"
for item in resp_1_data['items']:
# concat ID to the URL string
url = '{}{}'.format(base_url_2, item['id'])
# make the HTTP request
resp_2 = requests.get(
url,
headers={
"Headout-Auth": HEADOUT_TEST_API_KEY
})
resp_2_data = resp_2.json()
Product.objects.get_or_create(
title=item['name'],
destination=item['city']['name'],
description=resp_2_data['contentListHtml'][0]['html'], # this is what needs to be formated
link=item['canonicalUrl'],
image=item['image']['url']
)
return render(request, "form.html")
我该如何实现?
请帮助。