Giter Club home page Giter Club logo

flask_vote_app's Introduction

Your First Python Web App: Conor McGregor vs. Floyd Mayweather Flask Voting App + Heroku

Here are your instructions

  1. download the latest version of python from https://www.python.org/downloads/ and then install it. Also, make sure to check the ADD TO PATH box when going through the installation wizard.

  2. Create an account on Heroku.com

  3. MAC USERS ONLY: Install homebrew if you don't have it already with sudo /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  4. MAC USERS ONLY: Open up your terminal with cmd + space then type in terminal and then Install the heroku CLI client with brew install heroku and press enter in the terminal

  5. WINDOWS USERS ONLY: To install Heroku CLI Client on windows just go to https://devcenter.heroku.com/articles/heroku-cli#windows and click the 64-bit or 32-bit link to download and install

  6. WINDOWS USERS ONLY: Open your command line by hitting the windows key and typing in cmd or powershell.

  7. Type in git in your command line either on mac or windows and see if you get an error. If you do get an error, go online and type in install git. Then get git either for windows or mac by clicking one of the search results that pop up.

  8. At this point, Git and Heroku should be working!

  9. Now in your terminal or command prompt, enter the command git clone https://github.com/CleverProgrammer/flask_vote_app

  10. Now navigate to the project folder using cd flask_vote_app

  11. Enter the command: heroku login and provide your heroku login details. Note: When you type in password the cursor in the command line doesn't move. Don't freak out lol just type in your password for Heroku anyway.

  12. Now after you are logged in, use heroku create to create a new heroku application for you.

  13. push the code to heroku using git push heroku master

  14. Now make your own database where the votes will be stored with heroku addons:create heroku-postgresql

  15. Now launch the web app online: heroku ps:scale web=1

  16. Here is a little tricky and advanced part but don't worry so much about understanding it yet... Then in your terminal, you’ll need to run migrations for your db schema, to do this simply type heroku run bash on your terminal

  17. Once the terminal loads enter the command python init_db.py

  18. Now press ctrl + d to exit out of the heroku bash thing.

  19. BOOOOOOM! Your site is now on Heroku. Type in heroku open to go check it out online woohoo!!

flask_vote_app's People

Contributors

cleverprogrammer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

flask_vote_app's Issues

Operational Error

The error message is

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file

(Background on this error at: https://sqlalche.me/e/14/e3q8)

It says the error is on line
fighters = Fighter.query.order_by('id').all()

My Run.py File is configured like this
`import os
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy

app = Flask(name)

DATABASE_URL is by default

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///tmp/test.db'
db = SQLAlchemy(app)

#app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get'DATABASE_URL', 'sqlite:///tmp/test.db'

class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(120), unique=True)

def __init__(self, email):
    self.email = email

def __repr__(self):
    return '<User %r>' % self.email

class Fighter(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(120), unique=True)

class Vote(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
user = db.relationship('User', backref=db.backref('votes', lazy='dynamic'))
fighter_id = db.Column(db.Integer, db.ForeignKey('fighter.id'))
fighter = db.relationship('Fighter', backref=db.backref('votes', lazy='dynamic'))

@app.route('/', methods=['GET', 'POST'])
def homepage():
fighters = Fighter.query.all()
return render_template('index.html', fighters=fighters)

if name == 'main':
app.run(debug=True)`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.