Original link:
http://www.cnblogs.com/ymjr/p/5539731.html
- Run command-line tool, type: pip install virtualenv - installation virtualenv library.
- virtualenv blog_project_venv - virtualenv use to create a virtual environment
- blog_project_venv \ Scripts \ activate - enter the virtual environment just created
- pip install django - django installed in a virtual environment
- django-admin.py startproject blog_project - Creating a project
- python manage.py startapp blog - create an app
- Enter the blog folder, create a new folder named 'templates', which put the web app, and then create a new folder named 'static', which put this app in the css, js, img other documents
- Modify setting.py
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles',
# 添加第六步创建的app名字 'blog', ] TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', ' DIRS ' : [
# file created in Step Seven pages put the folder 'templates' associated with django profile os.path.join (base_dir, ' Templates ' ), ], ' APP_DIRS ' : True, ' the OPTIONS ' : { ' context_processors ' : [ ' django.template.context_processors.debug ' , ' django.template.context_processors.request ' , ' django.contrib.auth.context_processors.auth ' , ' django.contrib.messages.context_processors.messages', ], }, }, ]
# Seventh step will create a discharge css, js, img files associated with the folder django profile up STATICFILES_DIRS = ( the os.path.join (base_dir, ' static ' ), ) - Set add Home
blog_project \ the urls.py from django.conf.urls Import URL from django.contrib Import ADMIN
# introduction page read from a function views.py index from blog.views Import index the urlpatterns = [ URL (R & lt ' ^ ADMIN / ' , admin.site.urls), url (r ' ^ $ ' , index, name = ' index ' ) ]
Blog \ views.py from django.shortcuts Import the render # the create your views here Wallpaper.
# index creation function reads the home page def index(request): return render(request, 'index.html', locals()) - Change the static template pages
{% load staticfiles %} <!doctype html> <html> <head> <meta charset="utf-8"> <title>某某某的个人博客</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link href= "{% static 'css/base.css' %}" rel="stylesheet"> <link href="{% static 'css/index.css' %}" rel="stylesheet"> <script type="text/javascript" src="{% static 'js/jquery.min.js' %}"></script> <script type="text/javascript" src="{% static 'js/sliders.js' %}"></script> <!--[if lt IE 9]> <script src="{% static 'js/modernizr.js' %}"></script> <![endif]--> </head>
- Command line positioning to create a project folder blog_project, run the command: python manage.py runserver
- Enter in the browser '127.0.0.1:8000' into the web page
Reproduced in: https: //www.cnblogs.com/ymjr/p/5539731.html