https://jeong-pro.tistory.com/155

Posted by 마인드파워
,

 

example of a Python Flask application that uses a PostgreSQL database to store the daily work of employees:

 

import psycopg2
from flask import Flask, request, render_template
app = Flask(__name__)

def get_conn():
    conn = psycopg2.connect(
        host="localhost",
        database="daily_work",
        user="postgres",
        password="secret"
    )
    return conn

@app.route("/")
def index():
    return render_template("index.html")

@app.route("/submit_work", methods=["POST"])
def submit_work():
    work = request.form["work"]
    conn = get_conn()
    cur = conn.cursor()
    cur.execute("INSERT INTO work (description) VALUES (%s)", (work,))
    conn.commit()
    cur.close()
    conn.close()
    return "Work submitted successfully!"

if __name__ == "__main__":
    app.run()

This code uses the Flask web framework and the psycopg2 library to interact with a PostgreSQL database. The get_conn function returns a connection to the database, and the submit_work route uses this connection to insert the work submitted by the employee into the work table. You'll need to create this table and the daily_work database using a tool like the psql client or a GUI client like pgAdmin. The table can be created with the following SQL command:

 

CREATE TABLE work (
    id serial PRIMARY KEY,
    description text NOT NULL
);
<html>
  <head>
    <title>Enter daily work</title>
  </head>
  <body>
    <form action="/submit_work" method="post">
      <textarea name="work"></textarea>
      <input type="submit" value="Submit work">
    </form>
  </body>
</html>

 

sample code to show the contents stored in the PostgreSQL database as a table:

import psycopg2
from flask import Flask, render_template
app = Flask(__name__)

def get_conn():
    conn = psycopg2.connect(
        host="localhost",
        database="daily_work",
        user="postgres",
        password="secret"
    )
    return conn

@app.route("/")
def index():
    conn = get_conn()
    cur = conn.cursor()
    cur.execute("SELECT * FROM work")
    work = cur.fetchall()
    cur.close()
    conn.close()
    return render_template("work_table.html", work=work)

if __name__ == "__main__":
    app.run()

 

php

<html>
  <head>
    <title>Daily work</title>
  </head>
  <body>
    <table>
      <thead>
        <tr>
          <th>ID</th>
          <th>Description</th>
        </tr>
      </thead>
      <tbody>
        {% for row in work %}
        <tr>
          <td>{{ row[0] }}</td>
          <td>{{ row[1] }}</td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </body>
</html>

This code uses the Flask web framework and the psycopg2 library to interact with a PostgreSQL database. The index route retrieves the work stored in the work table using a SQL query, and the template work_table.html displays the work as a table.

Posted by 마인드파워
,

Android 앱 개발에 가장 적합한 도구는 개인 선호도와 프로젝트 요구 사항에 따라 다르지만 널리 사용되는 옵션은 다음과 같습니다.

  1. Android Studio: Android 앱 개발을 위한 공식 통합 개발 환경(IDE)입니다.
  2. React Native: JavaScript 및 React를 사용하여 네이티브 앱을 구축하기 위한 프레임워크입니다.
  3. Flutter: 단일 코드 베이스에서 고성능, 충실도, iOS 및 Android용 앱을 빌드하기 위한 오픈 소스 프레임워크입니다.
  4. Xamarin: C#을 사용하여 Android 및 iOS용 네이티브 앱을 만들 수 있는 플랫폼 간 개발 도구입니다.

궁극적으로 사용할 도구의 선택은 기술 능력, 예산 및 프로젝트 요구 사항에 따라 다릅니다.

 

 

'Developer' 카테고리의 다른 글

sample python code with PostgreSQL  (0) 2023.02.04
Posted by 마인드파워
,