An Interest In:
Web News this Week
- March 21, 2024
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
- March 15, 2024
August 10, 2022 06:37 pm GMT
Original Link: https://dev.to/omar_dev/bstkhdm-devto-nsh-mnshwr-jdyd-bythwn-14cg
devto
I always choose a lazy programmer to do the difficult job, because lazy programmer will find an easy way to do it.
bill gates.
dev.to
:
- dev.to api
- python
- localhost flask
cmd
pip install requests flask
flask
# from flask import Flask, render_templateimport requests# app = Flask(__name__)# html @app.route("/create", methods=['GET', 'POST'])def get_create(): if request.method == 'GET': return render_template('create.html')# if __name__ == '__main__': app.run(debug=True)
html ,
html
<!-- /templates/html ---><!-- tailwindcss ---><!DOCTYPE html><html> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <script src="https://cdn.tailwindcss.com"></script> </head> <body> <div class="root text-white bg-slate-900 h-screen w-full"> <div class="text-center text-3xl pt-5 font-bold">create a new post</div> <form class="flex text-blue-600 flex-col gap-2 mx-auto w-max pt-20" action="http://127.0.0.1:5000/create" method="post" > <input required type="text" name="title" placeholder="title" /> <textarea type="text" name="body_markdown" placeholder="body_markdown" ></textarea> <input required type="text" name="published" placeholder="published" /> <input required type="text" name="tags" placeholder="tags" /> <input required type="text" name="cover_image" placeholder="cover_image" /> <input type="submit" value="submit" /> </form> </div> </body></html>
python app.py
dev.to api key
api key
HtLrrPjaAfJdhxpTUJ5jKMxd
backend
## def Post_to_dev_to(title, body, tags, published, cover): headers = { 'api-key': 'HtLrrPjaAfJdhxpTUJ5jKMxd', # } json_data = { 'article': { 'body_markdown': """ --- title: {} published: {} tags: {} cover_image: {} --- {} """ .format(title, published, tags, cover, body), }, } response = requests.post('https://dev.to/api/articles', headers=headers, json=json_data)
@app.route("/create", methods=['GET', 'POST'])def get_create(): if request.method == 'POST': title = request.form['title'] body_markdown = request.form['body_markdown'] published = request.form['published'] tags = request.form['tags'] cover_image = request.form['cover_image'] Post_to_dev_to(title, body_markdown, tags, published, cover_image) return redirect(url_for('get_create')) else: return render_template('create.html')
python app.py
Original Link: https://dev.to/omar_dev/bstkhdm-devto-nsh-mnshwr-jdyd-bythwn-14cg
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To