如何使用python在postgresql中的单个id中添加多个值?

时间:2019-01-03 05:51:37

标签: python

我想在Postgresql中的单个ID中存储多个值。如果用户提供输入列表,则需要将其存储为单个ID。如何存储值列表?

Python函数

def e(clientdomain,k):
global b,j,s,d
c=1
for s in k:
    flash(s)
    for j in search(s, tld="com", num=100, stop=1, pause=2):
        domain=urlsplit(j)[1].split(':')[0]
        if clientdomain == domain:
            b=c
            d=j
            flash(d)
            flash(b)
            #print("The position of the google search result is:",b)
            #print("The full url:",d)
            #print("The keyword is:",s)
            #print("The date of search:",str(now))
        else:
            hasRank = False
        c=c+1
    c=0
if(hasRank == False):
        print("Uh oh, you're website is not ranked amoung the top 100 results. Sorry :-(")

用于创建数据库表

class urlkey112(db.Model):
id = db.Column('user_id', db.Integer, primary_key = True)
clientdomain = db.Column('clientdomain', db.String)
keyword = db.Column(db.String(100))
rank= db.Column(db.String(100))

要在数据库中存储值

    @app.route('/', methods = ['GET', 'POST'])
def urlkey1():
   form = UrlkeyForm()
   if request.method == 'POST':
       if not request.form['clientdomain'] or not request.form['keyword']:
          flash('Please enter all the fields', 'error')  
       else:
           clientdomain = request.form['clientdomain']
           keyword = request.form['keyword']
           k=keyword.split('\n')
           flash(k)
           #a=keyword[0:]
           #v=keyword[30:]
           #g.append(a)
           #g.append(v)
           #flash(g)
           e(clientdomain,k)
           #flash(b)
           #flash(d)
           #new = urlkey112(id=form.id.data, clientdomain=form.clientdomain.data, keyword=form.keyword.data, rank=b)
           #db.session.add(new)
           #db.session.commit()
           #flash('Record was successfully added')
           return redirect(url_for('urlkey1'))


   return render_template('key.html')

0 个答案:

没有答案