Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, render_template, request
- import psycopg2
- import traceback
- app = Flask(__name__)
- app.url_map.strict_slashes = False
- #login_manager = LoginManager()
- #login_manager.init_app(app)
- try:
- conn = psycopg2.connect(dbname='listings', user='matthew', host='103.16.128.240', password='zx34ghnm912')
- print("im connected")
- except psycopg2.Error as e:
- print("I am unable to connect to the database")
- print(e)
- print(e.pgcode)
- print(e.pgerror)
- print(traceback.format_exc())
- cursor = conn.cursor()
- templates = {"hairdresser":"demo-barber.html", "restaurants":"demo-restaurant.html", "engineering":"demo-engineering.html", "Accommodation":"accommodation.html"}
- @app.route('/<url_name>', subdomain="demo")
- def choose_template(url_name):
- business_data = get_business_data(url_name, cursor)
- template = templates[business_data['type']]
- print(business_data['logo'])
- return render_template(template, business_name=business_data['business_name'], email=business_data['email'], phone=business_data['phone'], location=business_data['location'], logo=business_data['logo'], url=url_name)
- def get_business_data(url_name, cursor):
- conn = psycopg2.connect(dbname='listings', user='matthew', host='103.16.128.240', password='zx34ghnm912')
- cursor = conn.cursor()
- business_data = {}
- cursor.execute("SELECT * FROM listings WHERE url=%s;", (url_name,))
- fetched_listings = cursor.fetchone()
- business_data['business_name'] = fetched_listings[0]
- business_data['email'] = fetched_listings[2]
- business_data['phone'] = fetched_listings[3]
- business_data['location'] = fetched_listings[4]
- business_data['type'] = fetched_listings[5]
- business_data['logo'] = fetched_listings[6]
- business_data['url'] = fetched_listings[7]
- return business_data
- @app.route('/<url_name>/<subpage>', subdomain="demo")
- def render_subpage(url_name, subpage):
- business_data = get_business_data(url_name, cursor)
- subpage_file = "%s.html" % subpage
- return render_template(subpage_file, business_name=business_data['business_name'], email=business_data['email'], phone=business_data['phone'], location=business_data['location'], logo=business_data['logo'], url=url_name)
- #@login_manager.user_loader
- #def load_user(user_id):
- # return User.get(user_id)
- #@app.route("/", subdomain="admin")
- #def login():
- # # Here we use a class of some kind to represent and validate our
- # # client-side form data. For example, WTForms is a library that will
- # # handle this for us, and we use a custom LoginForm to validate.
- # form = LoginForm()
- # if form.validate_on_submit():
- # # Login and validate the user.
- # # user should be an instance of your `User` class
- # login_user(user)
- #
- # flask.flash('Logged in successfully.')
- #
- # next = flask.request.args.get('next')
- # # is_safe_url should check if the url is safe for redirects.
- # # See http://flask.pocoo.org/snippets/62/ for an example.
- # if not is_safe_url(next):
- # return flask.abort(400)
- #
- # return flask.redirect(next or flask.url_for('index'))
- # return flask.render_template('admin.html', form=form)
- if __name__ == "__main__":
- app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement