当前位置: 首页 > 知识库问答 >
问题:

在EB上部署结构化Flask应用程序-查看函数映射错误

洪俊捷
2023-03-14

我最近一直在努力将我的Flask应用程序部署到AWS ElasticBeanstalk。我对网络项目和AWS还比较陌生,所以每天都很艰难。每隔一段时间,我会将我的项目部署到EB(我过去一直能够解决问题),但自从我从一个单一的应用程序重构我的应用程序以来。py对于更结构化的方法,我一直在努力。部署本身已成功,但我面临500个错误。日志上写着:

[Wed Apr 19 00:11:57.895790 2017] [:error]  mod_wsgi (pid=15947): Target WSGI script '/opt/python/current/app/app/members/views.py' cannot be loaded as Python module.
[Wed Apr 19 00:11:57.895846 2017] [:error]  mod_wsgi (pid=15947): Exception occurred processing WSGI script '/opt/python/current/app/app/members/views.py'.
[Wed Apr 19 00:11:57.895865 2017] [:error]  Traceback (most recent call last):
[Wed Apr 19 00:11:57.895881 2017] [:error]    File "/opt/python/current/app/app/members/views.py", line 14, in 
[Wed Apr 19 00:11:57.895903 2017] [:error]      @application.route('/')
[Wed Apr 19 00:11:57.895909 2017] [:error]   File "/opt/python/run/venv/lib/python2.7/site-packages/flask/app.py", line 1080, in decorator
[Wed Apr 19 00:11:57.895921 2017] [:error]      self.add_url_rule(rule, endpoint, f, **options)
[Wed Apr 19 00:11:57.895935 2017] [:error]   File "/opt/python/run/venv/lib/python2.7/site-packages/flask/app.py", line 64, in wrapper_func
[Wed Apr 19 00:11:57.895944 2017] [:error]      return f(self, *args, **kwargs)
[Wed Apr 19 00:11:57.895949 2017] [:error]   File "/opt/python/run/venv/lib/python2.7/site-packages/flask/app.py", line 1051, in add_url_rule
[Wed Apr 19 00:11:57.895956 2017] [:error]     'existing endpoint function: %s' % endpoint)
[Wed Apr 19 00:11:57.895969 2017] [:error]  AssertionError: View function mapping is overwriting an existing endpoint function: index

我的应用程序结构是:

myApp/
   runServer.py
   requirements.txt
   app/
      __init__.py
      config.py
      static/
      members/
         __init__.py
         views.py
         models.py
      templates/

我的


option_settings:
  "aws:elasticbeanstalk:container:python":
    WSGIPath: app/members/views.py

最后,我的视图。py文件包含所有我的url路由。我已确保所有函数名都相同。

有人知道我在看什么样的问题/解决方案吗?我能提供更多的信息来帮助你吗?

谢谢!

编辑:在视图中更改我的def index()函数。pytodef newFunctionForTesting()yieldsAssertionError:View函数映射正在覆盖现有endpoint函数:newFunctionForTesting

编辑2:可能与此类似,但在这种情况下,建议的解决方案是将所有内容写入一个文件中,这不是我想要的方法。。。也许蓝图能更有效。。。

编辑3:以下是我的应用程序的外观。

app\__init__. py



    from flask import Flask, flash, request
    from urlparse import urlparse, urljoin
    from urllib2 import urlopen
    from flask_user import SQLAlchemyAdapter, UserManager, current_user
    import os
    from apscheduler.schedulers.background import BackgroundScheduler
    import pandas as pd
    from app.members.models import db, User, AcademicData, Role, UserRoles, Query
    from passlib.hash import bcrypt
    import datetime
    import json

    # Initializes application
    application = Flask(__name__)
    application.config.from_object("app.config.Config")

    # Initializes db
    db.init_app(application)

    # Registers user model with db
    with application.app_context():
        db.create_all() # Creates tables defined
        db_adapter = SQLAlchemyAdapter(db, User)        # Register the User model

    @application.before_first_request
    def initialize():
        scheduler = BackgroundScheduler()
        scheduler.start()
        scheduler.add_job(updateData, trigger = "interval", days = 1)



    def updateData():
        ...


    @application.context_processor
    def injectFunction():
        def getDataTable(id):
            ...

    import members.views

    # Initialize flask-user
    user_manager = UserManager(db_adapter, application,register_view_function = members.views.protected_register)

app\members\views。py



    from flask import redirect, url_for, render_template, request
    from flask_user import login_required, roles_required, views as user_views
    from app import application, SITE_ROOT
    import json
    import os
    import pandas as pd

    @application.route('/')
    def index():
        """
        Index view. Currently the dashboard.
        :return: 
        """
        return redirect(url_for('dashboard'))

    @application.route('/dashboard')
    @login_required
    def dashboard():
        ...
        return render_template('dashboard.html')

    @application.route('/table')
    @login_required
    def table():
        return render_template('table.html')

    @application.errorhandler(404)
    def not_found(error):
         return render_template('404.html')

    @application.errorhandler(500)
    @application.errorhandler(503)
    def server_error(error):
        return render_template('503.html')

    @roles_required('admin')
    def protected_register():
        return user_views.register()


共有1个答案

谢志用
2023-03-14

我遵循这个例子来设置我的WSGIPath,但是自从@davidism指出了这一点,我尝试了一种不同的方法,并且成功了。我创建了一个app.wsgi文件,该文件基本上只是导入我的应用程序对象,并在我的中设置WSGIPath: app/app.wsgi

谢谢!

 类似资料:
  • 问题内容: 使用此处概述的步骤成功部署测试应用程序之后:http : //docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Python_flask.html 我尝试部署具有以下结构的实际flask应用程序: 其中包含我的网址映射。 我尝试在根目录以及模块中初始化实例,但是在AWS仪表板上收到以下错误: 应用程序无法正常工作(

  • 当我在glassfish 4.1中部署war文件时,会出现以下异常

  • 问题内容: 我正在尝试在Heroku上使用Flask开发我的第一个“大型”应用程序,并尝试将此处的基本教程与以下说明结合:https : //devcenter.heroku.com/articles/python与以下说明:http:// flask.pocoo.org/docs/patterns/packages/#larger- applications。它在本地与“先行启动”一起工作,但是

  • 问题内容: 谁能帮助我在IIS 6上运行Flask应用程序?我曾尝试使用isapi-wsgi,但是当我访问虚拟目录地址时,会得到一个页面,显示“找不到指定的模块”。还有其他选择吗? 以下是我为isapi-wsgi编写的Python脚本。已创建虚拟目录,并且在IIS管理器中一切正常,但该站点无法正常工作。 问题答案: 高层概述 HTTP-> IIS-> ISAPI-> FastCGI-> WSGI(

  • 当我部署flask应用程序时,它显示successful,但当我检索日志时,我看到错误“flask not found”。我的需求文件中有烧瓶。任何帮助。 [Sat Jan 11 06:51:50.503908 2020][:error][pid 3393][remote 127.0.0.1:0]mod_wsgi(pid=3393):目标wsgi脚本'/opt/python/current/app

  • 使用以下步骤成功部署测试应用程序后:http://docs.aws.amazon.com/ellasticbeanstalk/latest/dg/create_deploy_python_flask.html 我尝试部署实际的flask应用程序,该应用程序具有以下结构: