python request is not defined_Django“RequestContext”未定义-forms.ModelForm

我在尝试加载表单时遇到请求上下文错误。在my models.py上创建了ModelForm

已在我的视图上创建def加载项

链接到视图的url

视图.pydef add_company(request):

# Get the context from the request.

context = RequestContext(request)

# A HTTP POST?

if request.method == 'POST':

form = CompanyForm(request.POST)

# Have we been provided with a valid form?

if form.is_valid():

# Save the new category to the database.

form.save(commit=True)

# Now call the index() view.

# The user will be shown the homepage.

return index(request)

else:

# The supplied form contained errors - just print them to the terminal.

print form.errors

else:

# If the request was not a POST, display the form to enter details.

form = CompanyForm()

# Bad form (or form details), no form supplied...

# Render the form with error messages (if any).

return render_to_response('add_company.html', {'form': form}, context)

但是它被卡在了第一行。我做的和兰戈教程一样。好的。但我的不起作用。有什么线索吗?

谢谢

请求头:Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Encoding gzip, deflate

Accept-Language de,en-US;q=0.7,en;q=0.3

Cache-Control max-age=0

Connection keep-alive

Cookie csrftoken=I9120vmRATOck4a0SSqlfJPLl62PMUOR; sessionid=isx0p4ezb2y9m129v6243ui3ucuyvrak

Host localhost:8000

User-Agent Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:33.0) Gecko/20100101 Firefox/33.0

回应:Content-Type text/html

Date Sun, 07 Dec 2014 22:01:03 GMT

Server WSGIServer/0.1 Python/2.7.6

X-Frame-Options SAMEORIGIN

Request Method: GET

Request URL: http://127.0.0.1:8000/comp/new

Django Version: 1.7.1

Exception Type: NameError

Exception Value:

name 'models' is not defined

Exception Location: /home/mandaro/django/comp/company/forms.py in CompanyForm, line 5

Python Executable: /usr/bin/python

Python Version: 2.7.6

明白了:Problem wasn t on form - it was template import problem. Imported render_to_response instead of render solved it. Now it can goes on. ciao and tx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值