GithubHelp home page GithubHelp logo

django-backend's Introduction

Django-Backend

This is a popular python web framework for rapidly building web applications

Table of Contents

First-time Installation

We need uv package manager

  1. Set a virtual environment for the django project with the command
uv venv
  1. Activate the virtual environment
.venv\Scripts\activate
  1. If you face any error in Windows OS, open the windows-powershell as an administrator and type the following command
set-exectionpolicy remotesigned
  1. Install Django with the command
uv pip install Django
  1. Create a new Django project
django-admin startproject MyApp
  1. Come inside the project folder
cd MyApp
  1. Run the Django server
py manage.py runserver 
  • Use the above command whenever you want to restart the server(Dont forget to navigate to the manage.py's directory)

  • If some the port is bloacked for some reason then use a port number

py manage.py runserver 8001

To run subsequent times(After restarting the system)

You will need to use the following commands

 uv venv
.venv\Scripts\activate
  • Note: If you are not restarting the system, then use py manage.py runserver command

Django Architecture

  1. A project with the desired name is created, along a subfolder with the same name which contains - views.py: contains the core functionalities of the application(contains logic) urls.py: contains all routes settings.py: contains all settings

  2. db.sqlite3 is a default database for django which can also be migrated to postgres and mysql

  3. manage.py is the starting point of the application. It is the server

  4. static folder contains css and js files

  5. templates folder contains html files

Setting up static and template folders for use

  1. change this in settings.py to load css and js files
STATIC_URL = 'static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
  1. In index.html do the following changes
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MyApp | Django project</title>
    <link rel="stylesheet" href="{% static 'style.css' %}">
</head>
<body>
    <h1>This is a Django project</h1>
    
</body>
</html>
  1. In views.py do the following to render the html file on the browser
def home(request):
    return render(request, 'website/index.html')

TailwindCSS with Django

  1. Install pip and then tailwind css
  • Whichever the below command works use it
  • command 1
py -m ensurepip --upgrade
  • command 2
py -m pip install --upgrade pip

Note: use both when needed

  1. Install tailwind css with the following command
pip install 'django-tailwind[reload]'
  1. Go to settings.py and in apps object, add 'tailwind'

  2. Use this command to initiate tailwind in the server. Some packages will be installed along with a folder named theme if you keep the default settings

py manage.py tailwind init
  1. Go to settings.py and add 'theme' in the app section
  2. Next below it give the name of the tailwind app and InternalIP
TAILWIND_APP_NAME = 'theme'
INTERNAL_IPS = ['127.0.0.1']
  1. Use the command

django-backend's People

Contributors

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