They are helpful to keep packages and dependencies separate between different projects.ĭepending on your computer’s operating system, run the following commands: Windows: A virtual environment is an isolated environment for different Python projects. Next we’re going to create a virtual environment for this project and install the required dependencies. If you ever get lost, you can view the completed project here: Flask-Postgres App Open a command line tool and run the following commands: git clone Instead of starting from scratch, let’s make a copy of the Flask app I created by cloning the Github repo. It then renders the HTML pages contained in the Template folder using the Jinja Template library. The flask application I made first makes a request to the endpoints defined in the app/routes.py file to retrieve the data that is displayed in the registration form. I’ve created an example Flask app that renders a simple registration form used to collect information from a user.įlask is one of the most popular web frameworks written in Python. In this section we're going to create the Flask app shown above. Creating a Flask App for a Registration Form Flask app example Once you have all the above installed, we can start by setting up our development environment. This is where we will deploy the flask app and connect it to a remote Postgres database. Heroku Account: You need to create a free Heroku account if you do not already have one.Python 3.6 or newer: Python installers for different versions and OS are available for download here.A Postgres Database: You need to download and install Postgres on your local computer.You will need the following to follow along the tutorial: This guide is targeted towards beginner to intermediate programmers with some familiarity with programming and using the command line. If you’ve been looking to deploy your first web app to the cloud, this is a great place to start! Technical Requirements If this is your first time working with any of these technologies, I provide a brief explanation at the beginning of each section about how each technology works. Deploying the application to Heroku (hosting the application in the cloud so anyone can use it).Setting up a Postgres database with Python (store the data from the submitted forms).Creating a Flask app (web application for submitting the form).In the script You also don't use ActiveRecord.In this tutorial, I'm going to show how to make the web app and database shown in the gif above, and how to deploy it to Heroku so it can be used by anyone.Your config file is not doing anything in this approach.REMEMBER DON'T SET THOSE VALUES IN YOUR CODE Those can be retrieved from heroku postgresql configĬonnection = PG.connect(dbname: "makersbnb", host:, user:, password: ) You should specify not only dbname option but also: To connect to remote database You should specify some options in connection = PG.connect(dbname: "makersbnb") I will try to explain the problem, but also point some other flaws of Your current approach I also created a database.yml file based on other instructions I read but I'm not sure if it applies in this case: # database.yml file Gem "sinatra-activerecord" # for Active Record models Return unless BCrypt::Password.new(result) = password "SELECT * FROM users WHERE username = $1", User.new(user_id: result, username: result)ĭef thenticate(username:, password:) RETURNING user_id, username, password ",) Result = connection.exec_params("INSERT INTO users (username, password) Here is one of my lib file with my PG connections: require 'bcrypt'Ĭonnection = PG.connect(dbname: "makersbnb_test")Ĭonnection = PG.connect(dbname: 'makersbnb')Įncrypted_password = BCrypt::Password.create(password) Heroku pg:push makersbnb DATABASE -app makersbnb-challenge I migrated my db with the following command: Is the server running locally and accepting connections on that socket? When doing heroku logs -tail I’m having the following error message: PG::ConnectionBad - connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory I’ve deployed my Ruby app on Heroku, however when looking to register or login I’m having an internal server error.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |