Skip to content

Commit

Permalink
return json data
Browse files Browse the repository at this point in the history
  • Loading branch information
jakbin committed Feb 5, 2022
1 parent 5cd766f commit e3a6612
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
static/jquery.min.js
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
![GitHub Contributors](https://img.shields.io/github/contributors/jakbin/flask-ajax)
![GitHub commit activity](https://img.shields.io/github/commit-activity/m/jakbin/flask-ajax)
![GitHub last commit](https://img.shields.io/github/last-commit/jakbin/flask-ajax)
![Python 3.9](https://img.shields.io/badge/python-3.9-yellow.svg)
![flask 2.0.1](https://img.shields.io/badge/flask-2.0.1-green.svg)
![Python 3](https://img.shields.io/badge/python-3-yellow.svg)

## Features

Expand Down
21 changes: 15 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from flask import Flask, render_template, request, session, redirect, flash, url_for
from flask import Flask, render_template, request, make_response, json, Response
from flask_sqlalchemy import SQLAlchemy
import math
import os
import json
from datetime import datetime
from marshmallow import fields, Schema

app = Flask(__name__)
app.secret_key = 'super-secret-key'
Expand All @@ -20,14 +17,26 @@ class User(db.Model):
name = db.Column(db.String(80), nullable=False)
city = db.Column(db.String(80), nullable=False)

class UserSchema(Schema):
sno = fields.Int(dump_only=True)
name = fields.Str(required=True)
city = fields.Str(required=True)

user_schema = UserSchema()

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

@app.route("/loaddata")
def lodadata():
users = User.query.filter_by().all()
return render_template('loaddata.html', users=users)
# return render_template('loaddata.html', users=users)
data = user_schema.dump(users,many=True)
return custom_response(data, 200)

def custom_response(res, status_code):
return Response(mimetype="application/json",response=json.dumps(res),status=status_code)

@app.route("/insertdata", methods = ['POST'])
def insertdata():
Expand Down
9 changes: 0 additions & 9 deletions templates/loaddata.html

This file was deleted.

0 comments on commit e3a6612

Please sign in to comment.