Giter Club home page Giter Club logo

createing-your-first-django-project's Introduction

Creating Your First Django Web Project App

In this repo, you will learn how to create your first project in Django

Tools:

VS Code

Pre-Requisite:

Python3
Pip 

Verify it is installed or not, run below commands on cmd

python --version
pip --version

If not installed, then Download and install:

Python3 from  https://www.python.org/downloads/
Pip from https://pip.pypa.io/en/stable/installation/

Get Started With Django first project

mkdir "Django Project"
cd "Django Project"

Open vs code and type above commands on terminal

Setup virtual environment:

python -m venv venv
virtualenv venv
venv\Scripts\Activate

Note: Do Only if you face issue in creating virtualenv, run powershell as a admin

Run following command

get-ExecutionPolicy 		

if it give "restricted"

Run the following command

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

Type 'Y' to enable After enabling, run the following command get-ExecutionPolicy Now, it should give "remotesigned"

Now run the following command again

venv\Scripts\Activate (now you can see (venv)) in your terminal Img1

Installing Django

pip install django

Img2

Creating Project

djagno-admin startproject myproject

Change Directory to your project

cd myproject

Img3

Contents of myproject directory

Img4 Img5

Run Django server

python manage.py runserver [port]

Note: here port is optional, by default port is 8000 Img6

Run:

start localhost:8000/
start 127.0.0.1:8000/

e.g:

python manage.py runserver 9000		

Now it will run our django server with 9000

Run:

start localhost:9000/
start 127.0.0.1:9000/

Img7

By defaul Django project admin panel, we can check it using

start localhost:8000/admin/

Admin

Create App in django-project

django-admin startapp myapp

Img8

Now, Add 'myapp' in INSTALLED_APPS list of setting file of your project 'myapp'. Img9

Img10

Create urls.py file in myapp directory and write this code

from django.urls import path
from . import views

# URL endpoints for app
urlpatterns = [
	
]

Goto urls.py file of myproject directory, first import include from 'django.urls

Img11 from django.urls import path, include

In urlpatterns of urls.py of myproject, type

path('myapp/',include('myapp.urls')),

Img12

Now goto urls.py of myapp, and write url pattern

path('',views.index)

urls.py should look like:

from django.urls import path
from . import views

# URL endpoints for app
urlpatterns = [
	path('',views.index)
]

Goto views.py and write function

from django.shortcuts import render, HttpResponse

# Create your views here.
def index(request):
	return HttpResponse("Hello World")

Now goto, myproject directory and run the django server

python manage.py runserver

Open browser and type:

open localhost:8000/myapp/ or 127.0.0.1:8000/myapp/

Now, page will show "Hello World"

Img13

Congratulation:

You have done it. You have successfully created your first app in django.

Copyright: Ahsan Riaz

createing-your-first-django-project's People

Contributors

ahsanriaz9 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.