from flask import Flask, render_template, request,make_response,jsonify, redirect, url_for from pymongo import MongoClient from flask_wtf import FlaskForm, CSRFProtect from wtforms import StringField, FileField, DateTimeField from werkzeug.utils import secure_filename class BacheForm(FlaskForm): name = StringField('name') photo = FileField() class mongo_connection: conn = None def connect(self): mongoclient = MongoClient("mongodb://localhost:27017/") mongo_db = mongoclient["mapper"] self.conn = mongo_db["baches"] def query(self, sql): cursor = self.conn.find(sql) return cursor db = mongo_connection() db.connect() app = Flask(__name__) csrf = CSRFProtect(app) #mongodb_client = MongoClient("mongodb://localhost:27017/") #db = client['bachemap'] #collection = db['bachecitos'] @app.route("/", methods=['GET','POST']) def index(): if request.method == 'GET': return render_template("map.html") if request.method == 'POST': form=BacheForm() if form.validate_on_submit(): post_data = { 'author': form.author.data, 'img': form.img.data, 'latitude': form.latitude.data, 'longitude': form.longitide.data, 'message': form.message.data } collection.insert_one(post_data) flash('¡Gracias por tu aporte! A la ONU le gusta esto :3') return redirect(url_for('map')) return render_template('map.html', form=form) if __name__ == '__main__': app.run(host="localhost", port=5000, debug=True) # models schema: #{'latitude':'', 'longitude':'', 'severity':''}