Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to add CSS file and image file in Django?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 463
    Comment on it

    In Django framework first we create the project and follow these step shown below:

    Step1- First we create a project in your Django. If you are not able to create a project then use this link. This link helps to create a project in Django framework.

    Use this link show in given below,

    http://findnerd.com/list/view/How-to-create-project-in-dijango-1-4/15788/

    Step2- Then after in project we create the static file and configure static file in settings.py file in a project.

    Use this code show in below,

    STATICFILES_DIRS = (
        ('/home/sachin/Django-1.4/MYSITE/static'),
    
        # MYSITE is name of project in your django project
        # Put strings here, like "/home/html/static" or "C:/www/django/static".
        # Always use forward slashes, even on Windows.
        # Don't forget to use absolute paths, not relative paths.
    )
    

     

    Step3- Then we create a CSS folder in a static file and create a CSS file like base.css pass in a HTML file. And also put an image file in a static folder in Django.

    Use this code show in below:

    # **log.html file name**
    <html>
    <head>
    </head>
    <body>
        # this is your css file path
            {% load static from staticfiles %}
            <link href="{% static 'css/base.css' %}" rel="stylesheet" type="text/css"/> 
       
        # this is your Image file path in your django project
    	{% load static from staticfiles %}
    	<img src="{% static "/static/django-logo.png" %}" alt="Picture of Child" width="200" height="113" id="head_img" /> 
    
    
        #this is your text box as par your requirments
           <tr><td><b>username:</td><td><input type="text" name="username" value=""/>
            <tr><td><b>username:</td><td><input type="text" name="username" value=""/>
    
    
    </body>
    </html>
    # **base.css file is css file name**
    .head
    {
                  position:absolute;
                  top:-40%;
    	   left:28%;
    	}
    

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: