Web App Development Using Python and Django
Total Page:16
File Type:pdf, Size:1020Kb
WEB APP DEVELOPMENT USING PYTHON AND DJANGO A Project Presented to the Faculty of California State Polytechnic University, Pomona In Partial Fulfillment Of the Requirements for the Degree Master of Science In Computer Science By Karan Kohli 2020 SIGNATURE PAGE PROJECT: WEB APP DEVELOPMENT USING PYTHON AND DJANGO AUTHOR: Karan Kohli DATE SUBMITTED: Fall 2020 Department of Computer Science Dr. Lan Yang ____________________________________ Project Committee Chair Computer Science Dr. Yu Sun ____________________________________ Professor Computer Science ii ACKNOWLEDGEMENTS I would first like to thank my project advisor Professor Lan Yang whose valuable guidance helped me whenever I ran into a trouble spot or had a question about my project and coding. Professor Lan Yang consistently allowed this project to be my own work but steered me in the right the direction whenever he thought I needed it. I would also like to thank my committee member: - Professor Yu Sun, for the participation. Without their passionate participation and input, this project could not have been successfully conducted. iii ABSTRACT In today’s world there are so many people who want to be in fit, compete in the bodybuilding competitions, lose weight, and burn fat. However, there isn’t a proper platform where people can get all the needed information such as workout instructions, lifting technique, diet guidance, fitness plans according to each individual’s goals find the cheap dietary supplements and hire trainers/coaches. In this project, I developed a web-app to help people in achieving their fitness goals. The web-app, stay-fit.in, based Django, Python and SQL database technologies, provides users information with regard to fitness, diet, training and fitness related products buying. The project is aimed to provide an efficient, secure and scalable web-app design. iv TABLE OF CONTENTS SIGNATURE PAGE .......................................................................................................... ii ACKNOWLEDGEMENTS ............................................................................................... iii LIST OF FIGURES ........................................................................................................... vi CHAPTER 1 ....................................................................................................................... 1 Introduction to Framework ................................................................................................. 1 History of Django ............................................................................................................... 3 CHAPTER 3 ....................................................................................................................... 4 Django Framework ............................................................................................................. 4 CHAPTER 4 ....................................................................................................................... 7 Django Architecture ............................................................................................................ 7 CHAPTER 5 ..................................................................................................................... 13 Project Code ...................................................................................................................... 13 CHAPTER 6 ..................................................................................................................... 28 Project Working ................................................................................................................ 28 CHAPTER 7 ..................................................................................................................... 38 Conclusion ........................................................................................................................ 38 REFERENCES ................................................................................................................. 39 v LIST OF FIGURES Figure 1 (MVT Django) ...................................................................................................... 8 Figure 2 (File Structure of Django) .................................................................................... 9 Figure 3 (Google OAuth2 Authorization )........................................................................ 13 Figure 4 (App Settings in Django) .................................................................................... 14 Figure 5 (Authentication Backend for Oath2) .................................................................. 15 Figure 6 (Models Category) .............................................................................................. 16 Figure 7 (List View Setup) ............................................................................................... 17 Figure 8 (Urls for product app) ......................................................................................... 17 Figure 9 (Urls for main project directory) ........................................................................ 18 Figure 10 (Add to Cart View setup) ................................................................................. 18 Figure 11 (Adding Stripe for payment) ............................................................................ 19 Figure 12 (Payments URLS) ............................................................................................. 20 Figure 13 (Charge Function for handling payment) ......................................................... 20 Figure 14 (Django Signals) ............................................................................................... 22 Figure 15 (Signal Connections) ........................................................................................ 22 Figure 16 (Calories Forms) ............................................................................................... 23 Figure 17 (Models for Chat) ............................................................................................. 24 Figure 18 (Django Serializers) .......................................................................................... 25 Figure 19 (Views Setup for chat) ...................................................................................... 26 Figure 20 (View Setup for messages in Chat) .................................................................. 27 Figure 21 (Chat View for non- registered user) ................................................................ 27 vi Figure 22 (Homepage View) ............................................................................................ 28 Figure 23 (Login View) .................................................................................................... 29 Figure 24 (Add to cart) ..................................................................................................... 30 Figure 25 (In cart View) ................................................................................................... 30 Figure 26 (Add Address) .................................................................................................. 31 Figure 27 (Stripe Payment) ............................................................................................... 31 Figure 28 (Add Card Info) ................................................................................................ 32 Figure 29 (Order Status) ................................................................................................... 32 Figure 30 (Calorie Counter) .............................................................................................. 33 Figure 31 (Add Food Page)............................................................................................... 34 Figure 32 (Select Food) .................................................................................................... 34 Figure 33 (Chat View) ...................................................................................................... 35 Figure 34 (Admin Page for the trainer)............................................................................. 36 Figure 35 (Set Calorie goals) ............................................................................................ 37 vii CHAPTER 1 Introduction to Framework A web framework is a software that supports the development of a dynamic Web sites, applications and services. It provides a set of tools and functionalities that solves many common problems associated with Web development, such as security features, database access, sessions, template processing, URL routing, internationalization, localization and much more. 1. Why are Web Application Frameworks useful? A web framework is a code library that makes web development quicker and easily by giving basic patterns for building reliable, scalable and maintainable web applications. Web frameworks exist to make it easier for the developer to make a web application. Think of it to create shortcuts that can prevent otherwise overwhelming and repetitive code. For example, you may have written a code to handle data validation for your web application. In order to prevent having to re-write that code from scratch each time you make a website or web service, the web framework does it for you. A web framework differs from a web server in that a web server runs the web application, while the web framework is more like a virtual database or library