django-by-example-zh / django-by-example-zh Goto Github PK
View Code? Open in Web Editor NEW《Django By Example》个人翻译
《Django By Example》个人翻译
创建目录模板(templates) 下最后一个代码块中:
{% extends "shop/base.html" %}
{% load static %}
{% block title %}
{% if category %}{{ category.title }}{% else %}Products{% endif %}
{% endblock %}
{% block content %}
<div class="product-detail">
![]({% if product.image %}{{ product.image.url }}{% else %}{% static )
<h1>{{ product.name }}</h1>
<h2><a href="{{ product.category.get_absolute_url }}">{{ product.category }}</a></h2>
<p class="price">${{ product.price }}</p>
{{ product.description|linebreaks }}
</div>
{% endblock %}
其中
![]({% if product.image %}{{ product.image.url }}{% else %}{% static )
应该是
<img src="{% if product.image %}{{ product.image.url }}{% else %}{% static "img/no_image.png" %}{% endif %}">
我正在看,顺便修订下😁
In the code from email part, there is a line
request.build_absolute_url
However,build_absolute_uri()
should be the correct API, as far as I'm concerned.
Same part
return render(request, 'blog/post/share.html', {'post': post, 'form': form, 'sent': sent})
only post,form,sent is rendered to template: share.html
but in share.html, "{{ post.title }}" was successfully sent to {{ cd.to }}.
also involves cd
我可以转载到自己的网站吗?
署名,会贴上原地址。
就是自己看着方便
仓库为
author = models.ForeignKey(User,
related_name='blog_posts')
应当补充参数
author = models.ForeignKey(User, related_name='blog_posts', on_delete=models.CASCADE)
文章五分之四处,字符翻译错误, 原句为:
”只要你喜欢你可以连接许多模板标签(tempalte filters),每一个都会应用到上个输出生成的结果上。“
更正为:
”只要你喜欢你可以连接许多模板标签(template tag),每一个都会应用到上个输出生成的结果上。“
- 12 submitted: last submission 30 Mar 2017
Building a Blog Application | Section: Creating objects | Page no: 18 |Errata category: Code
The code given is:
>>> Post.objects.create(title='One more post',
slug='one-more-post',
body='Post body.',
author=user)
It should be as follows:
>>> post = Post(title='One more post',
slug='one-more-post',
body='Post body.',
author=user)
Enhancing Your Blog with Advanced Features | Section: Handling ModelForms in views | Page no:47 | Errata category: Technical
The sentence given is:
Edit the models.py file, add imports for the Comment model and the CommentForm form, and modify the post_detail view to make it look like the following:
It should be:
Edit the views.py file, add imports for the Comment model and the CommentForm form, and modify the post_detail view to make it look like the following:
Enhancing Your Blog with Advanced Features | Section: Adding comments to the post detail template | Page no: 49 | Errata category: Technical
The sentence given is:
Open the blog_detail.html template and append the following code inside the content block:
It should be:
Open the views_detail.html template and append the following code inside the content block:
Extending Your Blog Application | Section: Creating a search view | Page no: 83 | Errata category: Code
The code given is:
def post_search(request):
form = SearchForm()
if 'query' in request.GET:
form = SearchForm(request.GET)
if form.is_valid():
The code should be:
def post_search(request):
cd = None
form = SearchForm()
if 'query' in request.GET:
form = SearchForm(request.GET)
if form.is_valid():
Extending Your Blog Application | Section: Creating feeds for your blog posts | Page no: 74 | Errata category: typo
The sentence given is:
Navigate to http://127.0.0.1:8000/blog/feed/ in your browser. You should now see the RSS feedincluding the last five blog posts:
It should be:
Navigate to http://127.0.0.1:8000/blog/feed/ in your browser. You should now see the RSS feed including the last five blog posts:
Errata Type: Technical | Page 49 |
\1. The sentence given is: Now we need to adapt our post_detail.html template to do the following:
It should be: Now we need to adapt our post/detail.html template to do the following:
\2. The sentence given is: Open the blog_detail.html template and append the following code inside the content block:
It should be: Open the post/detail.html template and append the following code inside the content block:
\3. Errata for this mistakes on page https://www.packtpub.com/books/content/support/20895 has mistake Open the views_detail.html template and append the following code inside the content block:
It should be: Open the post/detail.html template and append the following code inside the content block:
On page 364 | Chapter 10 | Under section "Using mixins from django-braces"
Make OwnerCourseMixin inherit LoginRequiredMixin like this:
class OwnerCourseMixin(OwnerMixin, LoginRequiredMixin) :
Should be:
Make OwnerCourseEditMixin inherit LoginRequiredMixin like this:
class OwnerCourseEditMixin(OwnerMixin, LoginRequiredMixin) :
Extending Your Blog Application | Section: Using the filter() method | Page no: 18 | Errata category: code
The code given is:
Post.objects.filter(publish__year=2015)\
filter(author__username='admin')
It should be:
Post.objects.filter(publish__year=2015)\
.filter(author__username='admin')
Extending Your Blog Application | Section: Creating a search view | Page no: 84 | Errata category: typo
The sentence given is:
If the form is valid, we use the we use SearchQuerySet to perform a search for It should indexed Post objects whose main content contains the given query.
It should be:
If the form is valid, we use the SearchQuerySet to perform a search for It should indexed Post objects whose main content contains the given query.
Building a Social Website | Section: Log in and log out views | Page no: 100 | Errata category: code
The code given is:
Hello {{ request.user.first_name }},
It should be:
Hello {{ request.user.username }},
Extending Your Blog Application | Section: Creating custom template tags | Page no: 64-65 | Errata category: Typo
Our template tag will accept an optional count parameter that defaults to 5 and allows us to specify the number of comments we want to display.
The template tag we just created can be used passing the optional number of comments to display like {% show_latest_posts 3 %}.
Now, edit the blog/base.html template and add the new template tag to display the last 3 comments.
The template tag is called passing the number of comments to display and the template is rendered in place with the given context.
They should be:
Our template tag will accept an optional count parameter that defaults to 5 and allows us to specify the number of posts we want to display.
The template tag we just created can be used passing the optional number of posts to display like {% show_latest_posts 3 %}.
Now, edit the blog/base.html template and add the new template tag to display the last 3 posts.
The template tag is called passing the number of posts to display and the template is rendered in place with the given context.
Errata Type: Typo | Chapter 2 | Page 40
This:
request.build_absolute_uri
Should be:
request.build_absolute_url
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.