无法按计划时间在 Facebook 和 Instagram 上发帖,我可以按计划时间发帖,但我需要解决计划时间问题,不会出现任何错误。这是代码(VIEWS.PY)def...
无法按计划时间在 Facebook 和 Instagram 上发布帖子,虽然我可以按计划时间发布帖子,但我需要解决计划时间问题,不会出现任何错误。
以下是代码
(查看次数.PY)
def index(request):
post_form = BasicForm()
if request.method == 'POST':
post_form = BasicForm(request.POST, request.FILES)
try:
if post_form.is_valid():
fss = FileSystemStorage()
file = fss.save(request.FILES['post_file'].name, request.FILES['post_file'])
file_url = fss.url(file)
post_description = post_form.cleaned_data['post_description']
is_schedule = post_form.cleaned_data['schedule_check']
if is_schedule:
schedule_time = post_form.cleaned_data['schedule_time']
if schedule_time:
# Ensure schedule_time is timezone-aware
if timezone.is_naive(schedule_time):
aware_schedule_time = timezone.make_aware(schedule_time, timezone.get_default_timezone())
else:
aware_schedule_time = schedule_time
SchedulePost.objects.create(
post_description=post_description,
post_file=file_url,
fb_check=post_form.cleaned_data['fb_check'],
insta_check=post_form.cleaned_data['insta_check'],
whatsapp_check=post_form.cleaned_data['whatsapp_check'],
schedule_check=True,
my_datetime=aware_schedule_time,
)
logger.info(f"Scheduled time (selected): {aware_schedule_time.strftime('%Y-%m-%d %H:%M:%S %Z')}")
logger.info("Record scheduled...!")
return redirect('index') # Redirect to index after scheduling
(设置.PY)
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Karachi'
USE_I18N = True
USE_TZ = True
如果需要更多详细信息,请告诉我
[28/Jun/2024 02:17:11] \'GET /index/ HTTP/1.1\' 200 13741[28/Jun/2024 02:17:54] \'POST /index/ HTTP/1.1\' 302 0
尝试:第一步是将 USE_TZ = True 添加到您的设置文件中。还尝试了 naive_datetime 感知