Welcome to my final project for Harvard's CS50x course. This web application helps you create a password-protected portfolio and has two views: Admin view and Recruiter view.
You can log in as an Admin and do the following:
- Review drafts pages
- Add and delete recruiter logins
- Change admin password
- View history log of recruiter page visits
Using the logins you've set up, recruiters can log in and view your portfolio pages except the ones in draft.
Curious to see how this app works? Take a brief tour!
This project depends on the following technologies:
- Flask
- Python 3
- SQLite3
- Bootstrap 4.5
- HTML, CSS, and JavaScript
To use this application, you’ll need the following:
- Knowledge of HTML
- Basic understanding of CSS
- Basic command-line skills
Generally, you’d build your site in a local environment and deploy it when you’re ready. But we’ll work backwards in this tutorial for the benefit of users who might not have access to a local development environment.
-
Download this project to your computer.
-
Sign up for a free PythonAnywhere account, if you don’t already have one.
-
Log in to PythonAnywhere and from the Dashboard, open a new Bash console.
-
Create a virtual environment by executing the below command:
mkvirtualenv --python=/usr/bin/python3.6 my-virtualenv
-
After your environment is ready, install app dependencies by executing the below commands:
pip install Flask pip install Flask-Session pip install sqlalchemy
Don’t close this tab yet, we’ll come back to it soon.
-
Open a new tab and navigate to PythonAnywhere, and then click Files in the top-right corner.
-
Click Upload a file and upload the zip file you downloaded.
-
Switch to the Bash console and execute the following commands:
unzip portfoliobuilder-master.zip rm portfoliobuilder-master.zip
-
Go back to the other PythonAnywhere tab and click Web in the top-right corner.
-
Click Add a new web app and then click Next in app builder wizard. Don’t worry about the domain name for now.
-
Select Flask, then select Python 3.6, and then click Next. We’ll configure the app name later.
-
Switch to the Bash console in PythonAnywhere and execute the below command. Don’t forget to replace <your_account_name> in the below code with your PythonAnywhere account name.
cp -a /home/<your_account_name>/portfoliobuilder-master/. mysite rm -r /home/<your_account_name>/portfoliobuilder-master
-
Switch to the other PythonAnywhere tab, scroll down and open the WSGI configuration file.
-
Replace
flask_app
withapplication
as shown below and click Save.# import flask app but need to call it "application" for WSGI to work from application import app as application # noqa
-
Go back to the web app setup page and change the Working directory to
/home/<your_account_name>/mysite
. -
In the Virtualenv section, enter the path of your virtual environment. It looks something like this
/home/<your_account_name>/.virtualenvs/my-virtualenv
. -
Scroll to the top and click Reload <your_site>.
-
Click your site URL to view the app.
Upon initial login, you’ll be prompted to change the admin password.
-
Log in to your site with the following credentials:
Username: admin
Password: admin -
Set up a new password for the admin login. From now on, use this password to login as an admin.
Let's go ahead and personalise the site with your details.
-
Click Portfolio to view the page that lists your published portfolio items and browse the available layout options.
-
Navigate to your PythonAnywhere dashboard.
-
Select Files > mysite > templates > portfolio.html.
Delete tags between
<p class="font-weight-bold">Option #:</p> and </ul>
to remove the options you want to delete.
If you decide to go with Option 2, note that the image file names in the static folder must match the file names in theportfolio
folder, so that the template can pick the appropriate image. -
Navigate to the templates directory and replace John Doe with your name in the following files:
about.html layout.html
-
Navigate to the templates directory and add content in the following pages:
index.html privacy.html
Let's start building some portfolio pages. If required, brush up HTML and CSS skills at this stage.
- From your PythonAnywhere dashboard, select Files > mysite > templates > drafts > sample1.html.
- Add content within the main block of
sample1.html
.
To preview your changes, log in to your site, select Review drafts > sample1.
When you are happy with your draft, move them to the portfolio
folder.
If you're comfortable with the command line, you can physically move the file using a Bash console from your PythonAnywhere dashboard. Just remember to change the meta tags (front matter) at the beginning of the file (refer to one of the files within the portfolio
folder).
Or, you can copy the relevant HTML tags from the draft into one of the files within the templates/portfolio
folder.
When you’re ready with your shiny portfolio, you can share it with recruiters by creating a separate login for each recruiter. To do this, log in to your site, select Manage logins > Add new login.
If you have Python 3 installed and want to tinker with this project on your local machine, follow the below steps. For Python 2, refer to the Flask documentation and customise the below steps accordingly.
-
Create a folder and change directory:
$ mkdir mylocalpjt && cd mylocalpjt
-
Create a virtual environment and activate it:
$ python3 -m venv myflaskenv $ . myflaskenv/bin/activate
-
Install the dependencies within the virtual environment:
$ pip3 install flask Flask-Session sqlalchemy
-
Clone the project and change directory:
$ git clone https://github.com/deeptikorwar/portfoliobuilder && cd portfoliobuilder
-
Run the application locally:
$ python3 application.py
Open http://localhost:5000/ in your browser to view the app. You can use the procedures within Step 2 to Step 6 to build your portfolio (refer to the project file structure for file paths on the local machine). Once you're finished, you can replace these files on your PythonAnywhere site to update your public portfolio.
As you have limited space in your free PythonAnywhere account, free up space by deleting unused portfolio pages, images, and recruiter logins.
If your draft page or page within the portfolio directory is not rendered properly, check the meta tags and ensure that you’ve not missed anything.
If you forget the admin password, reupload the data.db
file from this repo to Files > mysite and log in with the initial admin logon credentials (admin, admin).
To reorder the items within the portfolio page, prefix file names with a number. For example, 1page.html, 2page.html. If you are using the card layout in your Portfolio page, remember to use 1page.png and 2page.png for files within the images folder.
Browse through the Bootstrap documentation and make use of the various prebuilt components offered by Bootstrap.
├── application.py
├── data.db
├── helpers.py
├── query.py
├── README.md
├── static
│ ├── favicon.ico
│ ├── images
│ │ ├── proc1.png
│ │ └── proc2.png
│ └── styles.css
└── templates
├── about.html
├── addlogin.html
├── admin.html
├── changepwd.html
├── confirmdel.html
├── drafts
│ ├── sample1.html
│ └── sample2.html
├── drafts.html
├── history.html
├── index.html
├── layout.html
├── login.html
├── manage.html
├── portfolio
│ ├── proc1.html
│ └── proc2.html
├── portfolio.html
└── privacy.html
With thanks to the following extensions and toolkits:
CS50x Finance was used as a starting point for this project.
Deepti Korwar