Environment:
Request Method: GET
Request URL: http://localhost:8000/topics/1/
Django Version: 1.11.4
Python Version: 2.7.12
Template error:
In template /home/hu/learning_log/learning_logs/templates/learning_logs/base.html, error at line 0
Cannot resolve keyword 'date_added' into field. Choices are: data_added, id, text, topic, topic_id 1 : <p>
2 : <a href="{% url 'learning_logs:index' %}">Learning Log</a>
3 : <a href="{% url 'learning_logs:topics' %}">Topics</a>
4 : </p>
5 :
6 : {% block content %}{% endblock content %}
我隐藏了追溯
Exception Type: FieldError at /topics/1/
Exception Value: Cannot resolve keyword 'date_added' into field. Choices are: data_added, id, text, topic, topic_id
答案 0 :(得分:0)
我不确定您所使用的Django版本,但是解决方案应该在URLs.py中。使用id
代替date_added
。
像这样:
path('' ", ListView.as_view(queryset=Post.object.all().order_by(" id")[:10], template_name="blog/home.html),
因此,使用order_by("date_added")
代替order_by("id")