Blog

This article will Teach you that how can you Write your First application in Django.
First you will need to setup Python/django you can read article How to Setup Django/python. After that Follow the steps below.

1) Open Pycharm or you can download from here.

2) From the command line pycharm terminal, cd into a projects directory where you’d like to store your code, then run the following command:

$ django-admin startproject my_first_project

Command will create a my_first_project directory in your current directory , and your project file hierarchy will be just like that:

mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        wsgi.py

3) From the command line pycharm terminal run this command to start project.

$ python manage.py runserver

By doing so it will start the development server, and we can access it via localhost:8000

Open the browser, and Browse the Site.

4) Creating an admin user

First we’ll need to create a user who can login to the admin site. Run the following command:

$ python manage.py createsuperuser

Enter your desired username and press enter.

Username: admin

Next you will be asked for your email Address:

Email address: [email protected]

In final step you will be asked for Setting admin password and Confirm password.

Password: **********
Password (again): *********
Superuser created successfully.

Now, open a Web browser and go to “/admin/” on your local domain – e.g., http://127.0.0.1:8000/admin/. You should see the admin’s login screen:

You can Login into Admin panel.

My First Programe in Django

This tutorial will teach you how you can write first program in Django. In this tutorial we will Print Welocome message on Web page using django.
Step 1: Add Html File in templates Directory

Right Click templates directory and add welcome.html file

Step 2: Add Welcome View Url

Goto views.py file and add the following Code.just below “# Create your views here.”


def Welcome(request):

    message = "Welcome! To My First Django project"

    return render(request, 'welcome.html',{
        'message': message
    })

Step 3: Add Welcome Url

url(r'^(?i)welcome/$', Welcome.as_view(),name="welcome_url" ),

Goto url.py file and add the following line or any url you like.

Step 4: Show welcome message

Now Goto “welcome.html” file that we just created and print the variable that we passed in context of view


{ message }}

Step 4: Run the Project

Click play button to run the project or from terminal Enter this Command:

$ python manage.py runserver

Now, open a Web browser and go to “/welcome/” on your local domain – e.g., http://127.0.0.1:8000/welcome/. You should see the Welcome screen with Welcome message:

Next Tutorial. Django Blog Tutorial – Step by step beginners guide for Django blog.

Leave a Reply

Your email address will not be published. Required fields are marked *