2017-06-22 45 views
0

我開始從在我的燒瓶應用程序中使用標準的基本SQL切換到使用peewee和得到一個奇怪的錯誤我似乎無法找到任何有關信息。我的終結點工作正常,但當我嘗試去登陸頁面時,我得到「jinja2.exceptions.UndefinedError:'peewee.IntegerField對象'沒有屬性'標誌'」錯誤,因爲我切換到peewee燒瓶應用程序。 'peewee.IntegerField對象'沒有屬性'標誌'

這似乎是一些奇怪的與wtforms和peewee但我似乎無法找到類似的問題。提前致謝。

注一切都在一個文件中

我的模型:

class pipelineForm(FlaskForm): 
    pipeline = IntegerField('Pipeline ID') 
class Process(Model): 
    pipeline_id = IntegerField() 
    process_name= CharField(null = True) 
    log= CharField(null = True) 
    exit_code= IntegerField() 
    started= CharField(null = True) 
    finsihed= CharField(null = True) 

    class Meta: 
     database=db 

終點着陸頁:

@app.route('/bloodhound', methods=['GET','POST']) 
def index(): 
    form =pipelineForm() 
    print(form.errors) 
    if form.validate_on_submit(): 
     print(str(form.pipeline.data)) 
     return redirect(url_for('.display', pipelineId=form.pipeline.data))#'<h1>' + str(form.pipeline.data) + '</h1>' 
    return render_template('index.html',form=form) 

着陸頁:

{% extends "bootstrap/base.html" %} {%import "bootstrap/wtf.html" as wtf%} {% block content %} 
<!DOCTYPE html> 
<html lang="en"> 

<head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> 
    <meta name="description" content=""> 
    <meta name="author" content=""> 
    <link rel="icon" href="../../favicon.ico"> 

    <title>Narrow Jumbotron Template for Bootstrap</title> 

    <!-- Bootstrap core CSS --> 
    <link href="../../dist/css/bootstrap.min.css" rel="stylesheet"> 

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> 
    <link href="../../assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet"> 

    <!-- Custom styles for this template --> 
    <link href="jumbotron-narrow.css" rel="stylesheet"> 

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! --> 
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]--> 
    <script src="../../assets/js/ie-emulation-modes-warning.js"></script> 

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> 
    <!--[if lt IE 9]> 
     <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> 
     <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> 
    <![endif]--> 
</head> 

<nav class="navbar navbar-inverse"> 
    <div class="container-fluid"> 
     <div class="navbar-header"> 
      <a class="navbar-brand" href="/bloodhound">Bloodhound</a> 
     </div> 
     <ul class="nav navbar-nav"> 
      <li class="active"><a href="/bloodhound">Home</a></li> 
      <li><a href="#">Performance</a></li> 
     </ul> 
    </div> 
</nav> 

<body> 

    <div class="container"> 


     <div class="jumbotron"> 
      <h1>Welcome to Bloodhound!</h1> 
      <p class="lead">Enter a pipeline Id to get diagnostic information.</p> 
      <form class="input" method="POST" action="/bloodhound"> 
       <div class="input-group" style="width: 300px;"> 
        {{form.hidden_tag()}} {{wtf.form_field(form.pipeline)}} 
        <span class="input-group-btn" style="vertical-align: bottom;"> 
        <button class="btn btn-default" type="submit" >Go!</button> 
        </span> 

       </div> 
      </form> 


     </div> 



     <footer class="footer"> 
      <p>&copy; 2017 MITRE.</p> 
     </footer> 

    </div> 
    <!-- /container --> 


    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> 
    <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script> 
</body> 

</html> 
{% endblock %} 

完整的堆棧跟蹤

Traceback (most recent call last): 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/flask/app.py", line 1997, in __call__ 
    return self.wsgi_app(environ, start_response) 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/flask/app.py", line 1985, in wsgi_app 
    response = self.handle_exception(e) 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/flask/app.py", line 1540, in handle_exception 
    reraise(exc_type, exc_value, tb) 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise 
    raise value 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/flask/app.py", line 1982, in wsgi_app 
    response = self.full_dispatch_request() 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/flask/app.py", line 1614, in full_dispatch_request 
    rv = self.handle_user_exception(e) 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/flask/app.py", line 1517, in handle_user_exception 
    reraise(exc_type, exc_value, tb) 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise 
    raise value 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/flask/app.py", line 1612, in full_dispatch_request 
    rv = self.dispatch_request() 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/flask/app.py", line 1598, in dispatch_request 
    return self.view_functions[rule.endpoint](**req.view_args) 
  File "/home/patrick/process_tracker/api/tracker_api.py", line 201, in index 
    return render_template('index.html',form=form) 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/flask/templating.py", line 134, in render_template 
    context, ctx.app) 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/flask/templating.py", line 116, in _render 
    rv = template.render(context) 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/jinja2/environment.py", line 1008, in render 
    return self.environment.handle_exception(exc_info, True) 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/jinja2/environment.py", line 780, in handle_exception 
    reraise(exc_type, exc_value, tb) 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/jinja2/_compat.py", line 37, in reraise 
    raise value.with_traceback(tb) 
 File "/home/patrick/process_tracker/api/templates/index.html", line 1, in top-level template code 
    {% extends "bootstrap/base.html" %} {%import "bootstrap/wtf.html" as wtf%} {% block content %} 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/flask_bootstrap/templates/bootstrap/base.html", line 1, in top-level template 
 code 
    {% block doc -%} 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/flask_bootstrap/templates/bootstrap/base.html", line 4, in block "doc" 
    {%- block html %} 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/flask_bootstrap/templates/bootstrap/base.html", line 20, in block "html" 
    {% block body -%} 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/flask_bootstrap/templates/bootstrap/base.html", line 23, in block "body" 
    {% block content -%} 
  File "/home/patrick/process_tracker/api/templates/index.html", line 58, in block "content" 
    <!-- {{form.hidden_tag()}} {{wtf.form_field(form.pipeline)}} --> 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/jinja2/runtime.py", line 553, in _invoke 
    rv = self._func(*arguments) 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/flask_bootstrap/templates/bootstrap/wtf.html", line 36, in template 
    {% if field.flags.required and not required in kwargs %} 
  File "/home/patrick/enviroments/venv/lib/python3.5/site-packages/jinja2/environment.py", line 430, in getattr 
    return getattr(obj, attribute) 

回答

0

根據你的錯誤消息,本場

class pipelineForm(FlaskForm): 
    pipeline = IntegerField('Pipeline ID') 

pewee.IntegerField類型的,你婉它是IntegerField型WTForms的。如果您將兩個班級放在同一個文件中,您需要:

import pewee 
import wtforms.fields 
class pipelineForm(FlaskForm): 
    pipeline = fields.IntegerField('Pipeline ID') 
class Process(Model): 
    pipeline_id = pewee.IntegerField() # and so on 
+0

完美!將pipeline = IntegerField('Pipeline ID')'改爲'pipeline = wtforms.IntegerField('Pipeline ID')'解決了我的問題。 – patrick1378

相關問題