1

0x00 django -- creating your first django project


1.preparatory work


  • python3: we will use python 3.5 to develop this project

  • pycharm: install pycharm professional on your computer--->Pycharm downloads

  • linux: we will develop this project on linux

  • django: pip3 install django

2.use pycharm IDLE to start your project


open your pycharm and create a django project
图片描述

you will get a project
图片描述

3.modify the setting file ~/djangoCarl/settings.py

ALLOWED_HOSTS = [
    '127.0.0.1',
    'www.exampleCarlBenjamin.com'
]

4.create the index.html ~/templates/index.html like that

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Hello Django</title>
</head>
<body>
<h1>Hello Django</h1>

</body>
</html>

5.modify your views ~/application/views.py like that

# coding=utf-8
from django.shortcuts import render


# Create your views here.
def application(request):
    return render(request, 'index.html')

6.modify your urls ~/djangoCarl/urls.py like that

from django.conf.urls import url
from django.contrib import admin
from application.views import application

urlpatterns = [
    url(r'$', application, name='application'),
    url(r'^admin/', admin.site.urls),
]

7.cd to your workspace and

python3 manage.py runserver

8.You will see 127.0.0.1:8000
图片描述

9.Now you complete your first project of django


CarlBenjamin
1 声望3 粉丝

My name is Carl Benjamin. Let's Fly away for the coding life.