django-countries:Person()只需要1个参数(0) [英] django-countries: Person() takes exactly 1 argument (0 given)
问题描述
我正尝试第一次使用 django-countries应用程序与Django,但我我得到这个错误让我困惑。 $ / $
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b
我在项目的虚拟环境中通过pip安装了django-countries 2.1.2。
INSTALLED_APPS
INSTALLED_APPS =
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls',
'survey',
'django_countries',
)
我正在使用Django 1.6.4。
models.py
from django.db import model
from django_countries.fields import CountryField
class Person(models.Model):
country = CountryField()
def __unicode__ (self):
return self.country
views.py
从django.shortcuts导入render
从django.db导入模型
从django_countries.fields导入CountryField
from models import SexChoice,AgeChoice,RelationshipStatusChoice,Person
def Person(request):
age = AgeChoice()
sex = SexChoice )
relationship = RelationshipStatusChoice()
country = Person()
return render(request,'survey.html',{
'age':age,
'sex':sex,
'relationship':relationship,
'country':country,
})
survy.html
< html>
< body>
< h1>实验调查< / h1>
< form action =method =post>
{%csrf_token%}
< h3>你几岁?< / h3>
{{age.as_p}}
< h3>你是什么性别?< / h3>
{{sex.as_p}}
< h3>你当前的关系状态是什么?< / h3>
{{relationships.as_p}}
< h3>你来自哪个国家/地区?< / h3>
{{country.as_p}}
< input type =submitvalue =提交/>
< / form>
< / body>
< / html>
这与先前的问题相似,但我修正了一些问题,并更新了一些细节。我删除了以前的问题。
你有Person的模型类和Person的功能。将其中一个命名为别的东西(函数不应该从大写开始)。
看起来像Person这个函数需要一个请求
参数,你没有传入。我想你的意思是使用Person的类,但重新定义是混乱的东西。
I am trying to use the django-countries application with Django for the first time but I am getting this error which has me confused.
TypeError at /survey/
Person() takes exactly 1 argument (0 given)
I installed django-countries 2.1.2 via pip in a virtual environment for the project.
INSTALLED_APPS
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls',
'survey',
'django_countries',
)
I am using Django 1.6.4.
models.py
from django.db import models
from django_countries.fields import CountryField
class Person(models.Model):
country = CountryField()
def __unicode__(self):
return self.country
views.py
from django.shortcuts import render
from django.db import models
from django_countries.fields import CountryField
from models import SexChoice, AgeChoice, RelationshipStatusChoice, Person
def Person(request):
age = AgeChoice()
sex = SexChoice()
relationship = RelationshipStatusChoice()
country = Person()
return render(request, 'survey.html', {
'age': age,
'sex': sex,
'relationship': relationship,
'country': country,
})
survy.html
<html>
<body>
<h1>Experiment Survey</h1>
<form action="" method="post">
{% csrf_token %}
<h3>What age are you?</h3>
{{age.as_p}}
<h3>What sex are you?</h3>
{{sex.as_p}}
<h3>What is your current relationship status?</h3>
{{relationship.as_p}}
<h3>What country are you from?</h3>
{{country.as_p}}
<input type="submit" value="Submit" />
</form>
</body>
</html>
P.S. This is similar to an earlier question but I fixed a few issues and updated some details. I deleted the earlier question.
You have Person the model class and Person the function. Name one of them something else (and functions should not start with capitals anyway).
Looks like Person the function requires a request
parameter, which you're not passing in. I think you mean to be using Person the class, but the redefinition is confusing things.
这篇关于django-countries:Person()只需要1个参数(0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!