start django project
Posted tangpg
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了start django project相关的知识,希望对你有一定的参考价值。
1.django-admin startproject helloword 创建项目helloword
2.开始一个app,写一个hello world
python manage.py startapp hello
4.settings db
DATABASES = { ‘default‘: { ‘ENGINE‘: ‘django.db.backends.mysql‘, # 你的数据库引擎 ‘HOST‘: "localhost", # 你的数据地址,localhost代表本地 "PORT": 3306, # 端口, 数据库的默认端口一般是3306 "USER": "root", # 用户名 "PASSWORD": "123456", # 密码 "NAME": "study" # 库名 } } # CACHES = { # "default":{ # "BACKEND":"django_redis.cache.RedisCache", # "LOCATION":"redis://127.0.0.1:6379/", # "OPTIONS":{ # "CLIENT_CLASS":"django_redis.client.DefaultClient" # } # } # }
4.view
import json from django.shortcuts import render, redirect, reverse from django.http import HttpResponse from django.contrib.auth import authenticate, login, logout from django.contrib import messages # 错误提示信息 from django.views.decorators.csrf import csrf_exempt from io import BytesIO from django.views import View from django.forms.utils import ErrorDict from django.core.cache import cache from show.models import Book # Create your views here. class CacheVisit(View): """ 访问数据库缓存 from django.core.cache import cache """ def get(self, request): books = Book.objects.all() return render(request, ‘1.html‘, locals())
5. 1.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> * { margin: 0; padding: 0; } </style> </head> <body> {% for book in books %} {{ book.title }} {{ book.author }} {{ book.download_text }} {{ book.new }}<br> {% endfor %} </body> </html>
6.url路由
from django.conf.urls import url from django.contrib import admin from show import views as view urlpatterns =( url(r‘^admin/‘, admin.site.urls), url(r‘^show/‘,view.CacheVisit.as_view()), )
以上是关于start django project的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Django Summernote 中显示编程片段的代码块?
[异常解决] Make nRF51 DFU Project Appear "fatal error: uECC.h: No such file or directory"(代码片段
httpd Server not started: (13)Permission denied: make_sock: could not bind to address [::]:8888(代码片段
RuntimeError: An attempt has been made to start a new process before the current process has...(代码片段
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)(代码片段