Long March second step --django personal blog (Step One - Create a home page)

Original link: http://www.cnblogs.com/ymjr/p/5539731.html
  1. Run command-line tool, type: pip install virtualenv - installation virtualenv library.
  2. virtualenv blog_project_venv - virtualenv use to create a virtual environment
  3. blog_project_venv \ Scripts \ activate - enter the virtual environment just created
  4. pip install django - django installed in a virtual environment
  5. django-admin.py startproject blog_project - Creating a project
  6. python manage.py startapp blog - create an app
  7. 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
  8. 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 ' ), )
  9. 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())

     

  10. 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>

     

  11. Command line positioning to create a project folder blog_project, run the command: python manage.py runserver
  12. Enter in the browser '127.0.0.1:8000' into the web page

Reproduced in: https: //www.cnblogs.com/ymjr/p/5539731.html

Guess you like

Origin blog.csdn.net/weixin_30515513/article/details/94784010