zoukankan      html  css  js  c++  java
  • 在openshift上使用django+postgresql

    openshift上用的是django 1.7,数据库选择的是postgresql 9.2

    本地开发用的是sqlite3数据库,发布到openshift上后是没有数据的(本地的sqlite3数据库里的数据并没有添加到openshift的数据库里,因为服务端的是postgresql数据库)。那么怎么在openshift上操作postgresql数据库呢?Let's go!

    一、连接openshift上的应用

    $ rhc ssh myapp

    二、激活python虚拟环境

    source $OPENSHIFT_HOMEDIR/python/virtenv/venv/bin/activate

    三、开启django shell

    python "$OPENSHIFT_REPO_DIR"wsgi/manage.py shell

    进入界面:

    Python 3.3.2 (default, Mar 20 2014, 20:25:51) 
    [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    (InteractiveConsole)
    >>>

    在shell里就可以操作数据库了

    >>> from django.db import connection
    >>> cur=connection.cursor
    >>> cur
    <bound method DatabaseWrapper.cursor of <django.db.backends.postgresql_psycopg2.base.DatabaseWrapper object at 0x7f1fe2a175d0>>

    给postgresql的数据表里添加一条记录:

    >>> from myblog.models import Todolist
    >>> q=Todolist(title='hello world')
    >>> q
    <Todolist: hello world>
    >>> q.save()
    >>> q
    <Todolist: hello world>
    >>> Todolist.objects.all()
    [<Todolist: hello world>]

    --End--

  • 相关阅读:
    【Gamma】Scrum Meeting 5
    【Gamma】Scrum Meeting 4
    【Gamma】Scrum Meeting 3
    团队贡献分汇总
    【Gamma】Scrum Meeting 2
    【Gamma】 Scrum Meeting 1
    Beta阶段测试报告
    From scipy.misc import imread 中 ImportError: cannot import name imread的解决方法
    【软件工程】结对项目
    【软件工程】第一次阅读作业
  • 原文地址:https://www.cnblogs.com/ibgo/p/4287448.html
Copyright © 2011-2022 走看看