Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 10, 2022 06:37 pm GMT

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

:

  1. dev.to api
  2. python
  3. localhost flask


createing files

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

http://localhost:5000/create
first look in webpage

dev.to api key

  1. https://dev.to/settings/extensions

  2. generate api key
    generateing api key

  3. 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:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To