Django: TypeError topic() got an unexpected keyword argument 'topics_id'
来源:互联网 发布:手机淘宝已购买生成器 编辑:程序博客网 时间:2024/06/13 12:50
urls.py#coding=utf-8'''定义learning_logs的URL模式'''from django.conf.urls import urlfrom . import viewsurlpatterns = [#主页 url(r'^$',views.index,name='index'), #显示所有的主题 url(r'^topics/$',views.topics,name='topics'), #特定主题的详细页面 url(r'^topics/(?P<topics_id>\d+)/$',views.topic,name='topic'),]
views.py# -*- coding: utf-8 -*-from __future__ import unicode_literalsfrom django.shortcuts import renderfrom .models import Topic# Create your views here.def index(request):'''学习笔记的主页'''return render(request,'learning_logs/index.html')def topics(request):'''显示所有的主题'''topics=Topic.objects.order_by('date_added')context={'topics':topics}return render(request,'learning_logs/topics.html',context)def topic(request,topic_id):'''显示单个主题及其所有条目'''topic=Topic.objects.get(id=topic_id)entries=topic.entry_set.order_by('-date_added')context={'topic':topic,'entries':entries}return render(request,'learning_logs/topic.html',context)
models.py# -*- coding: utf-8 -*-from __future__ import unicode_literalsfrom django.db import models# Create your models here.class Topic(models.Model):'''用户学习的主题'''text=models.CharField(max_length=200)date_added=models.DateTimeField(auto_now_add=True)def __unicode__(self):'''返回模型的字符串表示'''return self.textclass Entry(models.Model):'''学到的有关某个主题的具体知识'''topic=models.ForeignKey(Topic)text=models.TextField()date_added=models.DateTimeField(auto_now_add=True)class Meta:verbose_name_plural='entries'def __unicode__(self):'''返回模型的字符串表示'''return self.text[:50]+"..."
urls.py中将?P<topic_id>匹配到的值存储到topics_id中
views.py接受正则表达式(?P<topic_id>\d+)捕获的值,使用get来获取到指定主题
urls.py与views.py中的参数需保持一致,上面代码中urls.py中的参数为topics_id,views.py中的参数为topic_id,所有报错
参考:https://stackoverflow.com/questions/37254829/django-got-an-unexpected-keyword-argument-id
阅读全文
0 0
- Django: TypeError topic() got an unexpected keyword argument 'topics_id'
- django got an unexpected keyword argument maxlength
- django-got an unexpected keyword argument ‘maxlength’
- TypeError: __init__() got an unexpected keyword argument ‘maxlength’
- TypeError: __init__() got an unexpected keyword argument ‘maxlength’
- TypeError: __init__() got an unexpected keyword argument ‘maxlength’
- TypeError: concat() got an unexpected keyword argument 'axis'
- 报错TypeError: pool_2d() got an unexpected keyword argument 'ws'
- TypeError: histogram() got an unexpected keyword argument 'new'问题
- TypeError: __init__() got an unexpected keyword argument 'syntax'
- TypeError:__init__() got an unexpected keyword argument 'xxx'
- TypeError: pivot_table() got an unexpected keyword argument 'rows'
- pip错误:TypeError: parse() got an unexpected keyword argument 'transport_encoding'
- TypeError: exchange_declare() got an unexpected keyword argument 'type'的解决办法
- pip错误:TypeError: parse() got an unexpected keyword argument 'transport_encoding'
- TypeError: __init__() got an unexpected keyword argument 'shape'
- Keras TypeError: run() got an unexpected keyword argument 'class_mode'
- TypeError: __init__() got an unexpected keyword argument 'shape'
- 双系统win7+UBUNDTU
- 堆排序
- Struts2入门基础小结2!
- SpringMVC+Ibatis+SPring Security开发框架搭建
- JavaScript基本语法
- Django: TypeError topic() got an unexpected keyword argument 'topics_id'
- 将fddb标注转换为VOC格式标注
- 题目112-指数运算
- 用python绘制词云
- c++基础之文件
- java基础复习笔记2
- Hadoop入门
- 大小写字母装换器
- jQuery动画效果-向右移动