Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

python - I want to send terminal print data to database

enter image description here

I'm new to Django, I have created a selenium project in which It automates mobile recharge. After completion of "recharge successful" I need it to send a successful receipt into my database. I used print(order_id.text) to get receipt in my terminal. now I don't know how to send that receipt to my database.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Probably the easiest way to implement this is with a custom management command [Django-doc]. In your amazon app, yoou can define a management command:

amazon/
    management/
        commands/
            amazonpay.py
    # …

In that amazonpay.py file, you then implement the custom management command:

# amazon/management/commands.amazonpay.py

from django.core.management.base import BaseCommand
from amazon.models import Amazon

class Command(BaseCommand):
    help = 'Some description...'

    def handle(self, *args, **options):
        # … run selenium …
        Amazon.objects.create(
            o=ord_id
        )

You can then run this command with:

python3 manage.py amazonpay

In fact runserver, makemigrations, etc. are all defined as management commands as well.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...