0
我的意愿是让一个选择菜单,如下因素选择:没有发现模块的Django模型要求
models.py
TITLE_CHOICES = (
('MR', 'Mr.'),
('MRS', 'Mrs.'),
('MS', 'Ms.'),
)
和hello.html
显示。不过,我不断收到此错误:ImportError: No module named hello
对象: #continuation models.py
class hello(models.Model):
title = models.CharField(max_length=3, choices=TITLE_CHOICES)
def __unicode__(self):
return self.name
上view.py请求:
from django.http import HttpResponse
from django.template.loader import get_template
from django.template import Context
from testApp.models import hello
from testApp.models.hello import title
from django.shortcuts import render_to_response
from django.template import RequestContext
def contato(request):
form = hello()
return render_to_response(
'hello.html',
locals(),
context_instance=RequestContext(request),
)
def hello_template(request):
t = get_template('hello.html')
html = t.render(Context({'name' : title}))
return HttpResponse(html)
我在INSTALLED_APPS
应用(setting.py
) :
INSTALLED_APPS = (
'testApp',
'hello',
)
A呃帮助表示赞赏。
它采空给出错误,当我验证,但是当我运行服务器,并尝试接取它返回的意见导入错误的hello.html的.py in:from testApp.models.hello import title' – ClaudioA 2013-04-29 02:23:42
异常类型:\t导入错误 异常值:\t 没有名为hello的模块 – ClaudioA 2013-04-29 02:23:58
也删除该行。 'hello'是一个类,不是一个模块,你不能从中导入任何东西。 'title'是hello类中的一个字段。您不会导入它,您可以从hello类中导入'hello'并访问'title'。 – 2013-04-29 02:40:10