Django css file link


Open command prompt in windows 

then in command prompt  type    d:  

and press enter .

and use following commands 

To create folder  myap -execute the following command:

D:\> mkdir myap

To  go  myap folder path -execute the following command:

D:\>cd myap 

To create a virtual environment for your project, open a new command prompt, navigate to the myap  folder where you want to create your project and then execute the following command:-

D:\myap>python -m venv env

In the command prompt, ensure your virtual environment is active, and execute the following command:

D:\myap>env\Scripts\activate

execute the following command to install django.

D:myap>pip install django

run the following command - This will create a myproject  directory in your current directory

D:\myap>django-admin startproject  myproject

then go to myproject folder path type following command :-


D:\myap>cd myproejct


To create your app, make sure you’re in the your project  directory &  type this command:


D:\myap\myproejct>python manage.py  startapp hello 

That’ll create a directory hello app folder inside my_project folder:

after it open your myap folder inside it you will see my_project folder 



and inside my_project folder you will see following structure:-

 

At the bottom of the file settings.py,  under your my_project folder  write the following:-


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/

STATIC_URL = 'static/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]


So far so good. Now go to the html file in the templates folder (in my app it is index.html), open it and on the top of it write “{% load static  %}”. Write this even before opening the tag, write it on the first line.


Then within the <head></head> 

tag write  <link rel=”stylesheet” href=”{% static ‘ok.css’ %}”> My head tag currently looks like this:-


write your html code like this for example index.html file:-


<html>
    <head>
        {% load static %}

        <link rel="stylesheet" href="{% static 'ok.css' %}">


    </head>
    <body>
       
       
        <h1 class="myclass">hello world how are you
           
        </h1>
       
    </body>
</html>


from urllib import request
from django.shortcuts import render,redirect
def index(request):
   
    data="50"
   
    request.session['paid']=data
 

    return render(request, "home.html",{'data':data})
Previous
Next Post »