• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python model.connect_to_db函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中model.connect_to_db函数的典型用法代码示例。如果您正苦于以下问题:Python connect_to_db函数的具体用法?Python connect_to_db怎么用?Python connect_to_db使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了connect_to_db函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: setUp

    def setUp(self):
        # Get the Flask test client
        self.client = app.test_client()

        # Show Flask errors that happen during tests
        app.config['TESTING'] = True

        # Connect to test database
        connect_to_db(app, "postgresql:///testdb")

        # Create tables from model
        db.create_all()

        # Import different types of data from seed file
        seed.load_users()
        seed.load_groups()
        seed.load_usergroups()
        seed.load_patterns()
        seed.load_invites()
        
        # Reset auto incrementing primary keys to start after seed data
        seed.set_val_user_id()
        seed.set_val_group_id()
        seed.set_val_usergroup_id()
        seed.set_val_pattern_id()
        seed.set_val_invite_id()
开发者ID:ltaziri,项目名称:Hackbright-FinalProject,代码行数:26,代码来源:flaskr_tests.py


示例2: setUp

    def setUp(self):
        """Stuff to do before every test."""

        self.client = app.test_client()
        app.config['TESTING'] = True

        # Connect to test database (uncomment when testing database)
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data (uncomment when testing database)
        db.create_all()
        example_data()

        with self.client as c:
        with c.session_transaction() as sess:
            sess['RSVP'] = True

    def tearDown(self):
        """Do at end of every test."""

        # (uncomment when testing database)
        db.session.close()
        db.drop_all()

    def test_games(self):
        result = self.client.get("/games")
        self.assertIn("Clue", result.data)
开发者ID:cristinamclarkin,项目名称:Flask-testing,代码行数:27,代码来源:tests.py


示例3: index

def index():
    model.connect_to_db()  # connect to database, using code from model
    # do I need the post id?
    # what exactly is happening here?
    posts = model.get_all_posts()

    return render_template("index.html", all_posts=posts)
开发者ID:joyjding,项目名称:ex_up_app,代码行数:7,代码来源:app.py


示例4: post_to_wall

def post_to_wall(username):
    model.connect_to_db()
    user_id = model.get_userid_by_name(username)
    post_input = request.form.get("content")
    author_id = session['username']
    model.create_wall_post(user_id, author_id, post_input)
    return redirect(url_for("view_user", username=username))
开发者ID:jonahaga,项目名称:Session_Lession,代码行数:7,代码来源:app.py


示例5: setUp

    def setUp(self):
        print "\n\n\n\n (2) DOING A SEARCH TEST \n\n\n\n"
        self.client = app.test_client()
        app.config['TESTING'] = True
        postgrespassword = os.environ['POSTGRES_PASSWORD']
        db_uri = 'postgresql://' + postgrespassword + '/test'
        connect_to_db(app, db_uri)

        db.create_all()

        load_regions()
        load_users()
        load_bestuses()
        load_categories()
        load_brands()
        load_products()
        load_tents()
        load_filltypes()
        load_gendertypes()
        load_sleepingbags()
        load_padtypes()
        load_sleepingpads()
        load_ratings()
        load_histories()
        load_test_postalcodes()
开发者ID:fwong03,项目名称:watermelon,代码行数:25,代码来源:camper_tests.py


示例6: setUp

    def setUp(self):

        print "(setUp ran)"
        self.client = server.app.test_client()          # Sets up fake test browser
        server.app.config['TESTING'] = True             # Makes a 500 error in a route raise an error in a test
        connect_to_db(app, "postgresql:///testdb")      # Connect to temporary DB
        db.create_all()
开发者ID:erinallard,项目名称:Hackbright_Project,代码行数:7,代码来源:tests.py


示例7: setUp

    def setUp(self):
        """Setup to do before every test."""

        # Get the Flask test client
        self.client = app.test_client()
        app.jinja_env.undefined = StrictUndefined
        app.jinja_env.filters['prettify_preference'] = prettify_preference

        # Show Flask errors that happen during tests
        app.config['TESTING'] = True

        # Connect to test database
        connect_to_db(app, db_uri="postgresql:///testdb")

        # start with empty db
        db.drop_all()
        # Create tables and add sample data
        db.create_all()
        # create db records for yarns, users, baskets, basket_yarns,
        #                       projects, and patterns
        create_example_data()
        # create db records for preferences and user_preferences
        load_preferences("test_data/preference_data.txt")
        load_user_preferences("test_data/user_preference_data.txt")
        load_group_events("test_data/group-events.csv")
开发者ID:karayount,项目名称:commuKNITty,代码行数:25,代码来源:test_server.py


示例8: register

def register():
    model.connect_to_db()

    if session.get("user_id"):
        return redirect(url_for('view_user', username=session.get("username")))
    else:
        return render_template("register.html")
开发者ID:katrinamariehh,项目名称:session_lesson,代码行数:7,代码来源:app.py


示例9: create_account

def create_account():
    username = request.form.get("username")
    password1 = request.form.get("password")
    password2 = request.form.get("password_verify")

    print "top of create account", username,password1,password2
    
    if len(username) < 1:
        flash("username must be longer than 0 characters")
        return redirect(url_for("register"))

    if password1 != password2:
        flash ("passwords must match, try again")
        return redirect(url_for("register"))

    
    else:
        print "I'm connecting to the database cause the passwords matched!"
        model.connect_to_db()
        if model.user_exists(username):
            flash ("That user already exists")
        else:
            model.create_new_account(username, password1)
            flash ("Welcome")
            
        model.CONN.close()

        return redirect(url_for("index"))
开发者ID:AnneQSmith,项目名称:session_lesson,代码行数:28,代码来源:app.py


示例10: view_user

def view_user(username):
    model.connect_to_db()
    user_id = model.get_user_by_name(username)
    posts = model.get_wall_posts(user_id[0])
    return render_template("wall.html", posts = posts,
                                        logged_in = session["user_id"],
                                        username = username)
开发者ID:gosiamigdal,项目名称:session_lesson-,代码行数:7,代码来源:app.py


示例11: setUp

    def setUp(self):
        """Stuff to do before every test."""

        # Get the Flask test client
        self.client = app.test_client()

        # Mock session

        # Connect to temporary database
        connect_to_db(app, "sqlite:///")

        # Create tables and add sample data
        db.create_all()
        sample_data()


        def _mock_grab_image_dimensions(filename):
            return (920, 764)

        self._old_grab_image_dimensions = server.grab_image_dimensions
        server.grab_image_dimensions = _mock_grab_image_dimensions

        def _mock_generate_thumb(filename, crop_thumb):
            return None

        self._old_generate_thumb = server.generate_thumb
        server.generate_thumb = _mock_generate_thumb
开发者ID:zewlie,项目名称:wildally-project,代码行数:27,代码来源:tests.py


示例12: view_user

def view_user(username):
    model.connect_to_db()
    owner_id = model.get_user_by_name(username)
    wallposts = model.get_wall_posts(owner_id)
    html = render_template("wall.html", wallposts = wallposts)
    # print "print in_view user fucntion"
    return html
开发者ID:amlsf,项目名称:HB_session_lesson_wallposting,代码行数:7,代码来源:app.py


示例13: setUp

    def setUp(self):
        """Do before every test."""

        # Get the Flask test client
        self.client = app.test_client()

        # Show Flask errors that happen during tests
        app.config['TESTING'] = True

        # Connect to test database
        connect_to_db(app, "postgresql:///testdb")
        db.create_all()

        # Make mocks
        def _mock_get_yelp_search_results(term, location, category_filter, limit):
            """Mocks search results of Yelp API call for one restaurant."""

            search_results = {"businesses": [{"rating": 4.5, "rating_img_url": "https://s3-media2.fl.yelpcdn.com/assets/2/www/img/99493c12711e/ico/stars/v1/stars_4_half.png", "review_count": 547, "name": "Saru Sushi Bar", "rating_img_url_small": "https://s3-media2.fl.yelpcdn.com/assets/2/www/img/a5221e66bc70/ico/stars/v1/stars_small_4_half.png", "url": "http://www.yelp.com/biz/saru-sushi-bar-san-francisco?utm_campaign=yelp_api&utm_medium=api_v2_search&utm_source=6XuCRI2pZ5pIvcWc9SI3Yg", "image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/5-ugy01zjSvudVsfdhmCsA/ms.jpg", "display_phone": "+1-415-400-4510", "id": "saru-sushi-bar-san-francisco", "location": {"city": "San Francisco", "postal_code": "94114", "country_code": "US", "address": ["3856 24th St"], "coordinate": {"latitude": 37.751706, "longitude": -122.4288283}, "state_code": "CA"}}]}
            return search_results

        def _mock_is_open_now_true(keyword, location):
            """Mocks Google Places API call to return True for current open status."""

            return True

        self._old_is_open_now = process_results.is_open_now
        process_results.is_open_now = _mock_is_open_now_true

        self.old_get_yelp_search_results = server.yelp.search_query
        server.yelp.search_query = _mock_get_yelp_search_results
开发者ID:anniehe,项目名称:wait-time,代码行数:30,代码来源:tests.py


示例14: post_to_wall

def post_to_wall(username):
    model.connect_to_db()
    wall_owner = model.get_user_by_name(username)
    current_user = session.get('user_id')
    wall_content = request.form.get("wall_content")
    model.add_wall_post(current_user, wall_owner, wall_content)

    return redirect(url_for('view_user', username=username))
开发者ID:katrinamariehh,项目名称:session_lesson,代码行数:8,代码来源:app.py


示例15: setUp

 def setUp(self):
     self.client = app.test_client()
     app.config['TESTING'] = True
     app.config['SECRET_KEY'] = 'BalloonicornSmash'
     # Connect to the database
     connect_to_db(app, db_uri=travis_db_uri)
     # Reset the world so we start with clean data
     seed_force(app)
开发者ID:nija,项目名称:hb-chatty,代码行数:8,代码来源:tests.py


示例16: setUp

    def setUp(self):

        # Connect to test database
        connect_to_db(app, "postgresql:///testdb")

        # Create tables and add sample data
        db.create_all()
        example_data()
开发者ID:sarahcstringer,项目名称:hackbright-project,代码行数:8,代码来源:unit_test.py


示例17: setUpClass

    def setUpClass(cls):
        """Initializes the test application."""
        cls.client = server.app.test_client()
        server.app.config['TESTING'] = True

        model.connect_to_db(server.app, db_name='chat_client_test')
        # Clear any data that may be in the database.
        model.db.drop_all()
开发者ID:KTAtkinson,项目名称:crypto-im,代码行数:8,代码来源:server_test.py


示例18: post_to_wall

def post_to_wall(username):
    model.connect_to_db()
    content = request.form.get("content")
    author_id = session['user_id']
    owner_id = model.get_user_by_name(username)
    model.create_new_post(owner_id, author_id, content)
    # redirect_string = "/user/%s" % username
    return redirect(url_for('view_user', username=username))
开发者ID:blythest,项目名称:session_lesson,代码行数:8,代码来源:app.py


示例19: add_task_create

def add_task_create():
    model.connect_to_db()
    title = request.args.get("title")
    user_id = request.args.get("user_id")
    created_at = request.args.get("datestamp")
    row = model.new_task(title, created_at, user_id)
    html = render_template("added_task.html")
    return html
开发者ID:thisgirlangie,项目名称:Tipsy,代码行数:8,代码来源:tipsy.py


示例20: view_post

def view_post(username):

    model.connect_to_db()
    post_text = request.form.get('post_text')
    author_id = session.get('user_id')
    owner_id = model.get_user_id_by_username(username)
    model.insert_post(owner_id, author_id, post_text)
    return redirect(url_for("view_user", username = username))
开发者ID:ktel1218,项目名称:session_lesson,代码行数:8,代码来源:app.py



注:本文中的model.connect_to_db函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python model.get_current_youtify_user_model函数代码示例发布时间:2022-05-27
下一篇:
Python model.connect_db函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap