django笔记
基础
- 安装django以后就可以用
django-admin
- 创建project:
django-admin startproject HelloWorld
- 创建app: ``
- 创建project:
- 引入当前目录的内容:
from . import views
- 安装xmlsec失败,先安装依赖:
brew install libxml2 libxmlsec1 pkg-config
, https://blog.csdn.net/yuyexiaohan/article/details/107145624 - Disallowed Host:
Invalid HTTP_HOST header: '127.0.0.1:8000'. You may need to add '127.0.0.1' to ALLOWED_HOSTS
- 修改settings.py->’ALLOWED_HOSTS’
- django admin app:
'django.contrib.admin'
- django admin后台地址:
http://localhost:8000/admin
- django admin的默认账号,没有。 需要通过命令创建:
python manage.py createsuperuser
- 给django manager添加命令Django : How can I see a list of urlpatterns?
- django admin列出所有的urls(rails routes等价物), 需要装django-extension:
pip install django-extensions
- 安装app, settings.py->INSTALLED_APPS, 添加
'django_extensions',
- Linkedin登录:
- 官方django例子, 需要把抛错的app删除,然后配置key&secret, 见下面.
- python social auth settings ~~~python # settings.py SOCIAL_AUTH_LINKEDIN_OAUTH2_KEY = ‘77xqioxxxxxxxx’ SOCIAL_AUTH_LINKEDIN_OAUTH2_SECRET = ‘zILxe7jcxxxxxxxx’ SOCIAL_AUTH_LOGIN_REDIRECT_URL = ‘/home/’ SOCIAL_AUTH_LOGIN_URL = ‘/’