zoukankan      html  css  js  c++  java
  • Python Pyramid with PostgreSQL

    I created an app on openshift. and then i added a postgreSQL cartridge there.

    using ssh username@ip which redhat provided i logged into the server.

    using command "export" to check out the postgreURL which looks like

    postgre://username:password@ip:port

    then store those information.

    To make postgreSQL run with pyramid web application
    (for ubuntu/mint/debian)
    We should install ../bin/easy_install psycopg2
     or ../bin/pip install psycopg2
           (but there may some packages we need before we install this package)


    Reference: http://pythonhosted.org/psycopg2/install.html#install-from-a-package
    We should install this first:
      sudo apt-get install libpq-dev
    (tool pg-config is inside of libpq-dev)
    To compile psycopg2 we also need:
      sudo apt-get install python3-dev (please notice that this should be python3-dev)

    Then
    in the virtualenv,

    ../bin/easy_install psycopg2

    After few minutes, it will be finished.


    to check it out: then you go
    ../bin/python

    >>>import psycopg
    >>>

    Nothing wrong there!
    Congrats! You've installed psycopg2 on your computer :)

    then
    change things in development.ini which is in the folder of your app
    then do this!
    #sqlalchemy.url = sqlite:///%(here)s/alchemy_proj.sqlite
    sqlalchemy.url = postgresql://[username]:[passwd]@[ip]:[port]


    and go add something in model.py like this:

    from sqlalchemy import (
        Column,
        Integer,
        Text,
        String, // add this line here
        )
    
    from sqlalchemy.ext.declarative import declarative_base
    
    from sqlalchemy.orm import (
        scoped_session,
        sessionmaker,
        )
    
    from zope.sqlalchemy import ZopeTransactionExtension
    
    DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
    Base = declarative_base()
    
    
    class MyModel(Base):
        __tablename__ = 'models'
        id = Column(Integer, primary_key=True)
        #name = Column(Text, unique=True)
        name = Column(String(255), unique=True)        // and add this line here
        value = Column(Integer)
    
        def __init__(self, name, value):
            self.name = name
            self.value = value
                                                              30,26         All


    then go
    ../bin/initialize_alchemy_proj_db development.ini

    this script will create database and sheets automatically according to development.ini

    then go

    ../bin/pserve development.ini --reload

    this means you go there and start a server . when the setting's changed there, the server will refresh the settings.

  • 相关阅读:
    linux查看CPU性能及工作状态的指令mpstat,vmstat,iostat,sar,top
    Linux vmstat命令实战详解
    dstat 性能监测工具
    sysstat 工具
    Linux命令详解----iostat
    Linux CPU实时监控mpstat命令详解
    Linux Top 命令解析 比较详细
    Linux统计/监控工具SAR详细介绍
    ubuntu 添加用户到已存在的组
    Ubuntu 14.04 使用速度极快的Genymotion 取代蜗牛速度的原生AVD模拟器
  • 原文地址:https://www.cnblogs.com/spaceship9/p/3006880.html
Copyright © 2011-2022 走看看