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/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/ #从现在起,我们将在 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/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: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'^$…
http://127.0.0.1:8000/boards/1/topics/102/reply/ 让我们在文本区域添加 Markdown 支持来改善用户体验. 你会看到要实现这个功能非常简单. 首先,我们安装一个名为 Python-Markdown 的库: pip install markdown #我们可以在 Post 视图的 model 中添加一个新的⽅法: #boards/models.py from django.db import models from django.utils.ht…
http://127.0.0.1:8000/boards/1/topics/1/reply/ http://127.0.0.1:8000/boards/1/topics/1/ #myproject/urls.py url(r'^boards/(?P<pk>\d+)/topics/(?P<topic_pk>\d+)/reply/$',views.reply_topic, name='reply_topic'), #boards/forms.py from .models import…
# myproject/settings.py LOGIN_REDIRECT_URL = 'home' EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' http://127.0.0.1:8000/login/ http://127.0.0.1:8000/signup/ http://127.0.0.1:8000/reset/ http://127.0.0.1:8000/reset/done/ http://127.…
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/ 这是我们在前一个教程绘制的线框图.我现在意识到这个可能是一个不好的例子,因为这个特殊的表单涉及…