http://127.0.0.1:8000http://127.0.0.1:8000/boards/1/http://127.0.0.1:8000/boards/2/http://127.0.0.1:8000/boards/3/ # myproject/urls.py from django.conf.urls import url from django.contrib import admin from boards import views urlpatterns = [ url(r'^$…
# myproject/settings.py LOGOUT_REDIRECT_URL = 'home' http://127.0.0.1:8000/logout/ # myproject/urls.py from django.conf.urls import url from django.contrib import admin from django.contrib.auth import views as auth_views from accounts import views as…
http://127.0.0.1:8000/boards/1/topics/62/reply/ 我觉得只添加内置的个性化(humanize)包就会很不错. 它包含一组为数据添加“人性化(human touch)”的工具集. 例如,我们可以使用它来更自然地显示日期和时间字段. 我们可以简单地显示:“2分钟前”,而不是显示整个日期. 首先,添加 django.contrib.humanize 到配置文件的INSTALLED_APPS 中. #myproject/settings.py INSTALL…
http://127.0.0.1:8000/boards/1/ #boards/models.py from django.utils.text import Truncator class Topic(models.Model): # ... def __str__(self): return self.subject class Post(models.Model): # ... def __str__(self): truncated_message = Truncator(self.me…
http://127.0.0.1:8000/signup/ django-admin startapp accounts INSTALLED_APPS = [ 'accounts', ] # myproject/urls.py from django.conf.urls import url from django.contrib import admin from accounts import views as accounts_views from boards import views…
http://127.0.0.1:8000/boards/1/ http://127.0.0.1:8000/boards/2/ http://127.0.0.1:8000/boards/3/ http://127.0.0.1:8000/boards/1/new/http://127.0.0.1:8000/boards/2/new/ http://127.0.0.1:8000/boards/3/new/ 这是我们在前一个教程绘制的线框图.我现在意识到这个可能是一个不好的例子,因为这个特殊的表单涉及…
http://127.0.0.1:8000/http://127.0.0.1:8000/boards/1/http://127.0.0.1:8000/boards/2/http://127.0.0.1:8000/boards/3/ <!--static/css/app.css--> .navbar-brand { font-family: 'Peralta', cursive; } <!--templates/base.html--> {% load static %}<!D…
http://127.0.0.1:8000/settings/account/ #好的,那么,这部分将是我们最后的一个视图.之后,我们将专心来改进现有功能. #accounts/views.py from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User from django.urls import reverse_lazy from django.u…
http://127.0.0.1:8000/boards/1/ #从现在起,我们将在 board_topics 这个视图中来操作. python manage.py shell from django.contrib.auth.models import User from boards.models import Board, Topic, Post user = User.objects.first() board = Board.objects.get(name='Django') for…
http://127.0.0.1:8000/boards/1/topics/2/posts/2/edit/ http://127.0.0.1:8000/ #boards/views.py from django.views.generic import UpdateView from django.utils import timezone class PostUpdateView(UpdateView): model = Post fields = ('message', ) template…