Basic Structure which covers in this blog, to create a Portfolio App:
- Why developer learn Django
- Model structure which used to create in Django website
- Create "Hello world App"
- What is model, view and templates
- Complete tree structure of Django App
Why developer learn Django
Django is an open-source python web framework used for rapid development,pragmatic, maintainable, clean design, and secures websites. A web application framework is a toolkit of all components need for application development. The main goal of the Django framework is to allow developers to focus on components of the application that are new instead of spending time on already developed components.
Model structure which used to create in Django website
Model structure which used to create Django is defined by using three model terms:
Model: Defines the data structure. This is usually a database and is the base layer to an application.
View: displays some or all of the data to the user with HTML and CSS.
Template: handles how the database and the view interact and handle all static files.
Create "Hello world App"
Before start to create hello world app, first we will cover how to install Django on windows and mac by using pip command.
Install Django framework in windows:
>pip install django==2.2
where 2.2 is the version of Django framework, which is change as per developer choice.
Install any python editor like pycharm or subline text or as per developer choice, But in this tutorial we preferred the pycharm because it is free open source and easy to use, and work place is fine.
In this step we will create project and app by usig following command"
>django-admin startproject HelloworldApp
Project folder is created cd and change path and run below command
>C:/path where you want to put project /myproject>python manage.py startapp helloworld
Tree structure after done this look like this:
Go to the terminal and run"
>python manage.py runserver
Url is generated, copy url and paste it into browser and run than show rocket launcher symbol, which show it work properly.
Now you are ready start any project as per your choice.
Create an App:
Here we provide complete line of code under this app:
Line of code which modify in setting.py
Add app name helloworld at last.
Create a View:
Views in Django are a collection of functions or classes inside the view.py file in your app directory. Each function or class handles the logic that gets processed each time a different URL is visited. Line of code to create a view:
Create a url:
The final step is to hook up your URLs so that you can visit the page you’ve just created. Your project has a module called urls.py in which you need to include a URL configuration for the helloworld app.
Run app: Run app and go to the web browser and paste generated url.
Now you see output screen look like that:
Congratulations, You’ve created your first Django app and hooked it up to your project
Add static file in your project:
By using static files we will able to give style in our project it support like images and html and css etc.
It makes your app more stylish and it also support bootstrap.
Place where we add code for static file:
setting.py file consist static file code and and we created static files insight template directory which located at project folder.
Template file location:
Create a Models:
Django models come with many built-in model field types .To create this model, we’ll create a new class in models.py and add the following in our fields.
Here we define basic models.py file structure for your better understanding:
Create Superuser and Migrate:
When model is created than after super user create and migrate it and run app.
>python manage.py createsuperuser
>python manage.py migrate
Your table structure is created you can check it through admin panel.
If you like Codersarts blog and looking for Assignment help,Project help, Programming tutors help and suggestion you can send mail at firstname.lastname@example.org.
Please write your suggestion in comment section below if you find anything incorrect in this blog post.