Tuesday, September 28, 2021

fastapi

 Reference:

 https://github.com/nofoobar/fastapi-course/tree/main/backend

#main.py from fastapi import FastAPI from core.config import settings app = FastAPI(title=settings.PROJECT_NAME,version=settings.PROJECT_VERSION) @app.get("/") def hello_api(): return {"msg":"Hello API"}

Now, let's understand what we did, We are creating an instance of FastAPI and initializing it with a title and a project version. Now, we can reference the 'app' as a fastapi class object and use it to create routes.

  • @app.get('/') is called a decorator. A decorator is used to provide extra functionality to a function. 
  • get here is called a verb. There are HTTP verbs that determine the functionality allowed for a request. In this case, get means "A user may connect to this home route to retrieve some information."

More on HTTP verbs:
GET:  Requests using GET should only retrieve data.

POST: The POST method is used to submit an entity to the specified resource, e.g. submitting a form.

PUT: The PUT method is used to update a database table record.

DELETE: The DELETE method deletes the specified resource.

Okay back to our project. Notice that we are importing something from a config file from a folder named core.

├─.gitignore └─backend/ ├─core/ │ └─config.py ├─main.py └─requirements.txt


We will store our project settings and configurations inside of this file named config.py.

#config.py class Settings: PROJECT_NAME:str = "Job Board" PROJECT_VERSION: str = "1.0.0" settings = Settings()















Friday, September 24, 2021

how to create python virtual environment ?

 https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/26/python-virtual-env/

pip install virtualenv
virtualenv mypython
source mypython/bin/activate

Django project

 Project = Several applications + configuration information 

Note:

The Django applications can be plugged into other projects .ie these are reusable.

( pluggable django applications ).

withour existing django project there is no chance of existing django application. before creating any application first we required to create project.

How to create Django project ?

django-admin

django-admin startproject firstproject





__init__.py:

It is a blank python script. Because of this special file name, Django treated this folder as python package.

Note: If any folder contains __init__.py file then only that folder is treated as python package. 


settings.py:

In this file  we have to specify all our project settings and configuration like installed applications, middleware configurations, database configurations etc.

urls.py:

Here we have to store all our url-patterns of our project.

For every view (web page) we have to define separate url-patterns. End user can use url-patterns to access our webpages.

wsgi.py:

wsgi ---> Web Server Gateway Interface

we can use this file while deploying our application in production on online server.

manage.py

The most commonly used python script is manage.py 

It is a command line utility to interact with Django project in various ways like to run development server, run tests , create migration etc.

How to Run Django Development Server ?













features of django framework

 Django was invented to meet fast moving newsroom deadlines, while satisfying the tough requirements of experienced web developers.

1) Fast 

2) Fully loaded 

3) Security

4) Scalability 

5) Versatile 

https://docs.djangoproject.com/en/2.1/intro/overview/

Install django 

python --version

pip install django

pip install django==1.11.9

python3 -m django --version


Django Project vs  Django Application 

A Django project is a collection of application and configurations which forms a full web application.

E.g: Bank Project 

A Django application is responsible to perform a particular task in our entire web application 

E.g: loan app, registration app, polling app etc.







Django

 Django is a free and open source web framework.

It is written in python.

It follows the Model-view-template ( MVT ) ARCHITECTURAL pattern.

It is maintained by the Django software foundation.

It is used by several top websites like youtube , google, dropbox, yahoo maps, mozilla, instagram, washington times, Nasa and many more.

https://www.shuup.com/blog/25-of-the-most-popular-python-and-django-websites/

Django was created in 2003 as an internal project at lowrence journal world news paper for their web development.

The original author of Django framework are: Adrian Holovaty , Simon Willison.

After testing this framework with heavy traffics, developers released for the public as open source framework on july 21st 2005.

The django was named in the memory of guitarist django reinhardt.


reference : djangoproject.com


Web application ( py)

 The applications which will provide services over the web are called web applications.

Eg: gmail.com, facebook.com

Every web application contains 2 main components.

1. Front-End

2. Back-End

1) Front-End

It represents what user is seeing on the website.

We can develop Front-End content by using the following technologies.

HTML, JS, CSS, JQuery and Bootstrap.

JQUERY AND BOOTSTRAP are advanced front-end technologies, which are developed by using HTML,JS,CSS, JQUERY and BOOTSTRAP.

2) Back End

It is the technology used to decide what to show to the end user on the front-end 

ie Backend is responsible to generate required response to the end user , which is displayed by the front-end.

Backend has 3 important components.

1. The language like Java, Python etc 

2. The framework like Django, Pyramid, Flask etc 

3. The database like SQLite, Oracle , MySQL etc.

For the Backend Language python is the best choice because of the following reasons: Simple and easy to learn , libraries and concise code.