Build your first Django site - QA
来源:互联网 发布:手机qq苹果在线软件 编辑:程序博客网 时间:2024/05/28 15:04
How to change admin password ?
Django provided a built-in admin module, we can change our password from command line:
python manage.py changepassword <username>
if you even forgot your username, then create another superuser:
python manage.py createsuperuser
How to set up virtualenv for project development?
There are two ways, basiclly. install virtualenv first
1. Basic
pip install virtualenv
Then, you need cd into your project folder, and then set up virtualenv using:
virtualenv <env>
This command will generate all virtualenv supported files under folder /,
use actiave and deactivate to start or stop virtualenv.
2. Use virtualenvwrapper
pip install virtualenvwrapper
virtualenvwrapper is a global virtualenv manager. you can create multiple virtualenvs, and switch among them. Before use this tool, you should change your ~/.profile:
source "/usr/local/bin/virtualenvwrapper.sh"export WORKON_HOME=~/Envs
Envs contains all the virtualenv settings.
Add a virtualenv:
mkvirtualenv <name>
then work on a virtualenv:
workon <name>
Deactivate by
deactivate
virtualenvmapper also provide more helpful commands for env, like lsvirtualenvs, rmvirtualenv.
See http://virtualenvwrapper.readthedocs.org/en/latest/ for more.
How to use Django-registration-redux?
The previous django-registration package is not work for django 1.8, we need to use Django-registration-redux.
Install django-registration-redux
Of course install pip install django-registration-redux
in your virtualenv.
Add to INSTALLED_APPS
Like config other apps in django, add app ‘registration’ to your settings.py
INSTALLED_APPS = ( ... 'registration',)
Add account email activation settings.
Still in settings.py
ACCOUNT_ACTIVATION_DAYS = 7 # One-week activation window; REGISTRATION_AUTO_LOGIN = True # Automatically log the user in.EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'EMAIL_USE_TLS = TrueEMAIL_HOST = 'smtp.gmail.com'EMAIL_HOST_USER = 'xxxxxxxx@gmail.com'EMAIL_HOST_PASSWORD = 'xxxxxxxxx'EMAIL_PORT = 587
EMAIL_BACKEND has more options, actually this setting is here https://docs.djangoproject.com/en/1.8/topics/email/, not related to the django-registration-redux package.
Well, it is not good to add our email and password in settings.py, I will definitely improve it.
Ok, go on, we need our templates, for django1.8, specify templates as follow:
Add TEMPLATES
Still in settings.py
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ os.path.join(os.path.dirname('__file__'), "templates") ], 'APP_DIRS': True, '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', ], }, },]
Along with it, create a templates folder under your project folder, and then download templates from here https://github.com/macdhuibh/django-registration-templates .
Add urls
Don’t forget to set urls.py
urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^accounts/', include('registration.backends.default.urls')),]
Start server and test
Then run
python manage.py migrate python manage.py syncdbpython manage.py runserver 8000
Your server is up, what you can do now is:
http://localhost:8000/accounts/login
you will see registration, activation, reset, login and so on.
- Build your first Django site - QA
- Build Your First App(a)
- Writing your first Django app--Django 第一步
- Build your First Game with HTML5
- Hello World! Build Your First iPhone App
- Hello World! Build Your First iPhone App
- Tutorial: Build Your First Tensorflow Android App
- Writing your first Django app, part 1
- Writing your first Django app, part 1
- [笔记]Writing your first Django app
- Writing your first Django app, part 1
- Writing your first Django app, part 2
- Build a mediawiki site on your own computer
- [Django] Tell your site how to load the template files?
- Python Django的使用:Writing your first Django app--实践
- Django 官方文档write your first Django app --1
- Django 官方文档write your first Django app --2
- Django 官方文档write your first Django app --3
- 第一集 机器学习的动机与应用
- c++面试
- 从CPU核心架构看2016年移动设备趋势,A72到底能带来什么?
- C++常见内存错误汇总
- Android Material Design ProgressBar 使用经验(导入,颜色自定义等)
- Build your first Django site - QA
- 关于ota搭建的苹果官方文档
- Java中的super()研究
- Go语言net/http 解读.
- Android url中文乱码问题及解决办法
- Cocos2d-x学习笔记(十三)—— 数据解析(json/xml)
- PCB焊盘、过孔、走线、去耦技术
- java接口和抽象类
- sql存储过程规范极其用应