Coder Social home page Coder Social logo

django-modules's Introduction

Django-Modules

All New Modules I tried on Django

First of all need to install Django & Django-admin (pip3 install)

first create a PROJECT :

django-admin startproject mysite

The project folder will be created with the files :

mysite/ manage.py mysite/ init.py settings.py urls.py asgi.py wsgi.py

Then create an app for the PROJECT:

python manage.py startapp myapp

The app folder will be created with the proper files :

myapp/ init.py admin.py apps.py migrations/ init.py models.py tests.py views.py

After this we need to create on urls.py file at myapp ,so that we can rediret our app specific urls,(templates etc)

cd myapp

touch urls.py --> insert --> save it

from django.urls import path

from . import views

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

[ Note :- here we redirect the home location to search at views.py for the index function ]

But First we need to tell our project that where to tranfer when any request come for the app :

so at mysite, edit urls.py -->

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

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

Now we need to create functi at views.py :

from django.http import HttpResponse

def index(request): return HttpResponse("Hello, world. You're at the polls index.")

We need to tell django which app to use for the deployment :

Go to mysite --> apps.py

class MyAppConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' name = 'myapp'

take classname from the file : copy it and paste in mysite --> settings.py

INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'myapp.apps.MyAppConfig', ]

Save it.

Now we can run our server for testing : with any specified port ->

python3 manage.py runserver 8080

without port also it will work :

python3 manage.py runserver

For configuring Templates and Static folder :

Create templates & static folders where manage.py files is present, and add there location to --> settings.py file.

add this to bottom

STATIC_URL = 'static/'

STATICFILES_DIRS = [ BASE_DIR / "static", ]

and Modify the templates as well :

TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ BASE_DIR / "templates", ], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ]

add your html files on templates and images, js, css, etc on static folder.

edit your views.py according to your templates

from django.http import HttpResponse, render

def index(request): return render(request, 'index.html')

django-modules's People

Contributors

yogendrashastri 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.