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.

  • 相关阅读:
    NS3系列—4———NS3中文教程5:Tweaking NS3
    NS3系列—3———NS3中文:4 概念描述
    NS3系列—2———NS3笔录
    NS3系列—1———NS3中文教程:3下载及编译软件
    How to speed my too-slow ssh login?
    Linux bridge
    使用 GDB 和 KVM 调试 Linux 内核与模块
    How To Set Up A Serial Port Between Two Virtual Machines In VirtualBox
    Linux内核调试环境搭建(基于ubuntu12.04)
    Android
  • 原文地址:https://www.cnblogs.com/spaceship9/p/3006880.html
Copyright © 2011-2022 走看看