Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django,以10为底的int()的文本无效:';用户';_Python_Django - Fatal编程技术网

Python Django,以10为底的int()的文本无效:';用户';

Python Django,以10为底的int()的文本无效:';用户';,python,django,Python,Django,查询集(视图) 我通过点击链接调用coin_profile 网址: urlpatterns = [ path('', views.index, name = 'index'), path('add_transaction/', views.add_transaction, name = 'add_transaction'), path('<user>/<coin>', views.coin_profile, name = 'coin_profile

查询集(视图)

我通过点击链接调用coin_profile

网址:

urlpatterns = [
    path('', views.index, name = 'index'),
    path('add_transaction/', views.add_transaction, name = 'add_transaction'),
    path('<user>/<coin>', views.coin_profile, name = 'coin_profile'),
]
返回此错误。
这意味着当我使用user=user时,queryset需要一个整数,但是为什么呢?如何将我的用户名传递给此查询?

如果传递给
coin\u profile
user
参数是一个user
name
(或其他一些用户属性),您可以使用如下内容

def coin_profile(request, username, coin):
    test = Transaction.objects.filter(user__username=username, coin=coin)

如果传递给
coin\u profile
user
参数是一个用户
name
(或其他一些用户属性),则可以使用如下内容

def coin_profile(request, username, coin):
    test = Transaction.objects.filter(user__username=username, coin=coin)

用于筛选的
用户
需要是
用户
模型的实例。根据错误判断,我猜您没有发送
用户
实例。

用于筛选的
用户
需要是
用户
模型的实例。根据错误判断,我猜您没有发送
用户
实例。

那么为什么它会期望非整数?那么为什么它会期望非整数?这将返回异常“异常值:相关字段获得无效查找:名称”。@SkillSet12345您可以如何调用
coin\u profile()
?你到底在传递什么?回答更新。请注意,我已将
coin_profile
参数
user
重命名为
username
,以明确其实际内容。这将返回异常“exception Value:Related Field got invalid lookup:name”。@SkillSet12345您可以如何调用
coin_profile()
?你到底在传递什么?回答更新。请注意,我已将
coin\u profile
参数
用户
重命名为
用户名
,以明确其实际含义。
class Transaction(models.Model):    
    user = models.ForeignKey(User, on_delete = models.CASCADE)  
def coin_profile(request, username, coin):
    test = Transaction.objects.filter(user__username=username, coin=coin)