Django 2.0

Creating the First Django Application

I am going to create an app named crmapp. First I change the directory to

cd CRM
source v_env/bin/activate
cd PrjCrm
django-admin startapp crmapp

Add the new app to the end of INSTALLED_APPS dictionary


Our new app does not have a So, create an empty file in crmapp folder first.

Every new application’s should be included to the main like below. To do that first import include class to main Then include the new app’s as a path in urlspattern like this.

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

urlpatterns = [
    path('crmapp/', include('crmapp.urls')),

Now we need to create a url, view and a template for our crm app. (crmapp’s

from django.urls import path
from crmapp import views

urlpatterns = [
    path('', views.crmapp, name='crmapp'),

from django.shortcuts import render
from django.http import HttpResponse

def crmapp(request):
    msg = "hello"
    return render(request, 'crmapp.html', {'welcome_msg':msg})

Create a folder named templates in crmapp folder. In templates folder, create a file named crmapp.html. The content of crmapp.html is below:

{% block title%}
    <title>Welcome To The Crm App!</title>
{% endblock title%}

{% block content %}
    <div class="container">
    {{ welcome_msg }}
{% endblock content %}

Restart Apache service

service apache2 restart

Post Comment