Django 1 - Setup, IP address

In this section, I'm going to show how to start off Django 


I recommend you to use "Visual Studio  or  Pycharm"  for python (I used Visual Studio, which is free and can be downloaded on google)


Making new project folder "New project" and type "django-admin startproject mysite"



"mysite" can be named as whatever you want


Now you're going to see some files inside of mysite file and I'm going to explain how they work later.


Next step is go to mysite folder path and type "python manage.py runserver"




you will see 

Django version 4.0.3, using settings 'mysite.settings'

Starting development server at http://127.0.0.1:8000/


"http://127.0.0.1:8000/" this is the IP address that connects your project with Django



If this page popped up, it means you're doing well. 

(you can also change the IP address by typing different number at the end )

ex) python manage.py runserve 9090 -> you'd get this address " http://127.0.0.1:9090/" 



Next, making new folder -> python manage.py startapp main

now you can see new directory inside of new project folder. 


1. go to main -> views.py  and  type 

"from django.http import HttpResponse"

"def index(response):

    return HttpResponse("<h1>Welcome to my world</h1>")"

it should be like this
from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.

def index(response):
    return HttpResponse("<h1>Welcome to my world</h1>")



2. making "urls.py" inside main folder.
"from django.urls import path
from . import views
urlpatterns = [
path("", views.index, name="index"),
]

from django.urls import path

from . import views

urlpatterns = [
path("", views.index, name="index")
]

New project is our project for our website
Main folder - is the application that links to our project


Inside of mysite - urls.py

from django.urls import path, include (to link this to our project)
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('main.urls')),

'', include('main.urls') means if don't type anything it will automatically direct to ourselves
to the main dor URLs file.

Save and go to the IP address again, now you're going to see "Welcome to the world" on the screen


Popular posts from this blog

[Python] Dictionary

[Visual Design 2/3]

[JavaScript] For loop , Function