not able to post on schedule time on Facebook and Instagram with schedule time i am able to post but i need to sort the schedule time issue not any error appears.
Here is the code
(VIEWS.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
(SETTING.PY)
LANGUAGE_CODE = 'en-us'TIME_ZONE = 'Asia/Karachi'USE_I18N = TrueUSE_TZ = True
Kindly let me know if any more details are required
[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
Tried : The first step is to add USE_TZ = True to your settings file.Also tried the naive_datetime aware as well