Saturday, April 5, 2025

I need the excel having multiple sheets but it was not done help me to do it

I have created the function to export the excel sheet separately now i need to combine the separate sheets into single excel file : 
when use this showing the 200 response but the excel file was not generated in my file so help me to fix it
@api_view (['POST']) 
@permission_classes([IsAuthenticated])
def export_combined_template(request):
# Create an in-memory output buffer
output = io.BytesIO()

# Get DataFrames from each export function
df_contractor = export_contractor_excel_sheet_template()
df_applicability = export_example_applicability_template()
df_incharge = export_incharge_owner_template()

# Optional: Log DataFrame shapes to verify data is present
print("Contractor DF shape:", df_contractor.shape)
print("Applicability DF shape:", df_applicability.shape)
print("Incharge DF shape:", df_incharge.shape)

# Use ExcelWriter to combine multiple sheets into a single Excel file
with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
# Write Contractor Template sheet
df_contractor.to_excel(writer, sheet_name='Contractor Template', index=False)
contractor_ws = writer.sheets['Contractor Template']
header_format = writer.book.add_format({'bold': True, 'align': 'center', 'valign': 'vcenter'})
for col_num, header in enumerate(df_contractor.columns):
contractor_ws.write(0, col_num, header, header_format)
contractor_ws.set_column(col_num, col_num, 18)
# Add dropdown validation for "Is Sub Contractor" (column index 4)
contractor_ws.data_validation(1, 4, 1048575, 4, {
'validate': 'list',
'source': ['Yes', 'No'],
'ignore_blank': True
})

# Write Applicability Template sheet
df_applicability.to_excel(writer, sheet_name='Applicability Template', index=False)
applicability_ws = writer.sheets['Applicability Template']
for col_num, header in enumerate(df_applicability.columns):
applicability_ws.write(0, col_num, header, header_format)
applicability_ws.set_column(col_num, col_num, 18)
# Add dropdown validation for "Is Enable" (column index 2)
applicability_ws.data_validation(1, 2, 1048575, 2, {
'validate': 'list',
'source': ['Yes', 'No'],
'ignore_blank': True
})

# Write Incharge Owner Template sheet
df_incharge.to_excel(writer, sheet_name='Incharge Owner Template', index=False)
incharge_ws = writer.sheets['Incharge Owner Template']
for col_num, header in enumerate(df_incharge.columns):
incharge_ws.write(0, col_num, header, header_format)
incharge_ws.set_column(col_num, col_num, 18)
# (Add additional formatting or validations for the incharge sheet if needed)

# Rewind the buffer to the beginning
output.seek(0)

# Build the HTTP response with the Excel file
response = HttpResponse(
output.read(),
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
)
response['Content-Disposition'] = 'attachment; filename="combined_templates.xlsx"'
return response

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/django-users/9211a987-fd5a-4089-8678-0293ef3b4e24n%40googlegroups.com.

Friday, April 4, 2025

Re: Problem with static files inDjango-Oscar

​When deploying a Django project with DEBUG = False, static files are not served automatically by Django. To handle static files in production, you can use WhiteNoise. After installing WhiteNoise, add 'whitenoise.middleware.WhiteNoiseMiddleware' to your MIDDLEWARE settings and set STATICFILES_STORAGE to 'whitenoise.storage.CompressedManifestStaticFilesStorage'. Then, run python manage.py collectstatic to collect all static files into the directory specified by STATIC_ROOT. This setup enables WhiteNoise to serve your static files efficiently in a production.
On Monday, 31 March 2025 at 1:14:32 am UTC+5:30 Szawunia wrote:
Hi everybody,
I have problem with my static files in my Django project, running local. Actually Django-Oscar, but settings files is Django.  There are not founded (404 error). I have all my static files in my project directory (where 'manage.py' is).
My settings:

STATIC_URL = 'static/'

STATIC_ROOT = BASE_DIR / 'static'

In my templates:

{% load static %}

<link href="{% static "main.css" %}" rel="stylesheet">

<link rel="shortcut icon" href="{% static "logo3.gif" %}" />

I stuck with that problem. Earlier in my Django simple project, all was ok. So my settings should be right. 

Any help will be appreaciate. Or any idea how to check, in simple way, what is wrong with my static loading

With all the best 


Ewa


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/django-users/ba691a4c-c066-4521-8e71-95fc8ed7c1cen%40googlegroups.com.