Skip to content

bwoldemi/Django-projects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 

Repository files navigation

Step by step guide for creating a a Django project

creating project mysite

django-admin startproject mysite

Check the created project running the server, the default port is 8000

python manage.py runserver

To run the server in port other than the defalut port.

python manage.py runserver 8080

To run the server in a certain ip address

python manage.py runserver 0:8000

Creating application name: polls

python manage.py startapp polls

configuring polls application

on views.py create a method index which handles the view

from django.http import HttpResponse`
def index(request):
     return HttpResponse("Hello, world. You're at the polls index.") 

To create a URLconf in the polls directory, create a file called urls.py under polls directory:

from django.urls import path

from . import views

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

In mysite/urls.py, add an import for django.urls.include and include url file

from django.contrib import admin
from django.urls import path, include


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

Creating database for polls app

from django.db import models

Create your models here.

class Question(models.Model):
    question_text = models.CharField(max_length=100)
    pub_date= models.DateTimeField('date published')

class Choice(models.Model):
    question= models.ForeignKey(Question, on_delete=models.CASCADE)
    choice_text = models.CharField(max_length=200)
    vote = models.IntegerField(default=0)

Commit the following command to create the database and the models

python manage.py makemigrations polls
python manage.py sqlmigrate polls 0001

Crating the supper user

python manage.py createsuperuser

Make the poll app modifiable in the admin¶

polls/admin.py

Creating templete

create a directory under the applcation with the name templates, and then create another directory which similar to the application. The templete html files goes in this directory.

polls/templates/polls/index.html

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published