This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
orm.RegisterDataBase("db1", "mysql", "root:root@/orm_db2?charset=utf8") | |
orm.RegisterDataBase("db2", "sqlite3", "data.db") | |
o1 := orm.NewOrm() | |
o1.Using("db1") | |
o2 := orm.NewOrm() | |
o2.Using("db2") | |
// After switching database |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (c *UserController) GetOne() { | |
o := orm.NewOrm() | |
var user models.User | |
idStr := c.Ctx.Input.Param(":id") | |
// 만일 파람으로 넘어온 키값으로 얻은 유저이름이 다르거나 | |
// 또는 관리자나 슈퍼유저가 아닌경우에 401에러를 날립니다 | |
// 현재 세션은 메모리로 하기때문에 60초 뒤에 날라감 | |
// mysql로 설정 변경 필요 | |
username := c.GetSession("Username") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (this *TestController) Show3() { | |
o := orm.NewOrm() | |
var arc []*models.Archives | |
o.QueryTable("go_archives").Filter("Id__gt", 1).RelatedSel().All(&arc)//使用RelatedSel将关联的arctype也查出来,也就是left join arctype as T1 on T1.id=go_archives.arctype_id | |
arc3 := arc[0] | |
fmt.Println(arc3.Arctype.Typename) | |
}// 이런식으로해서 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"github.com/astaxie/beego" | |
) | |
func (c *AdminController) Logindo() { | |
username := c.GetString("username") | |
c.SetSession("Adminname", username) //设置Session | |
adminName := c.GetSession("Adminname") //读取Session | |
c.DelSession("Adminname") //删除Session | |
c.TplNames = "admin/login.html" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"beegoorm/models" | |
"fmt" | |
"github.com/astaxie/beego" | |
"github.com/astaxie/beego/orm" | |
_ "beegoorm/routers" | |
_ "github.com/go-sql-driver/mysql" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import os | |
import unittest | |
import mock | |
import pytest | |
from fots import abc_urandom, my_random |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import os | |
from os import urandom | |
import mock | |
import unittest | |
import pytest | |
from fots import abc_urandom |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from os import urandom | |
import mock | |
def simple_urandom(length): | |
return 'f' * length | |
class TestRandom(unittest.TestCase): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = ['Hello', 'Sydney', 'I', 'Am'] | |
b = [1, 2, 3, -1212.022, 5523, 232441, 1000] | |
# way 1 방법1 | |
with open("foo.txt", "w") as f: | |
map(lambda var: f.write(str(var)) if var == b[-1:][0] else f.write(str(var) + " "), b) | |
# way 2 방법2 | |
with open("foo.txt", "w") as f: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 보면 이런식으로 여러줄의 라인을 한 줄로 만들 수 있습니다. | |
# style 1 | |
current_id = return_response.data["id"] | |
current_banking = LOLOBanking.objects.get(id=current_id) | |
current_banking.related_id = withdraw_account_id | |
current_banking.withdraw_type = withdraw_type | |
current_banking.bank_type = wa.bank_type | |
current_banking.save |