最简单的方式来编写一个访问Django数据库功能的Python程序 [英] Easiest way to write a Python program with access to Django database functionality
问题描述
什么是最简单的方法Python程序可以访问我的特定Django应用程序和Django ORM?
from django .core.management import setup_environ
from django.core.mail import EmailMultiAlternatives,send_mail
from django.contrib.auth.models import User
import settings
from my .app.models import *
setup_environ(settings)
这是怎么回事我做了一个电子邮件通知各方每日更新。 .py居住在我的django应用程序的根目录,所以导入设置将反映出来。
I have a website which fetches information from RSS feeds periodically (well, currently manually, and this is my problem). This is currently implemented as a normal Django view, which isn't very nice in my opinion. I'd like to have a Python program which is run using a cronjob instead of manually visiting the correct URL to update the information.
What is the easiest way to make a Python program have access to my particular Django application and the Django ORM?
from django.core.management import setup_environ
from django.core.mail import EmailMultiAlternatives, send_mail
from django.contrib.auth.models import User
import settings
from my.app.models import *
setup_environ(settings)
This was how I did it for a cron that emailed parties daily updates. The .py lived in the root of my django app, so the import settings would reflect that accordingly.
这篇关于最简单的方式来编写一个访问Django数据库功能的Python程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!