Skip to content

Commit 60b208c

Browse files
committed
fix pdf page with docker
1 parent ca4ea8b commit 60b208c

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
APP_ENV = 'dev'
22
APP_SECRET_KEY = 'fsdfsda32@!#@zrf42c9+n4(^4mlo_@8(t'
33
APP_URL = 'http://127.0.0.1:8000'
4+
PDF_URL = 'https://nginx'
45
ALLOWED_HOSTS = localhost 127.0.0.1 [::1]
56
CSRF_TRUSTED_ORIGINS = http://127.0.0.1:8000
67

8+
79
TWITTER_CONSUMER_KEY = ''
810
TWITTER_CONSUMER_SECRET = ''
911
TWITTER_ACCESS_TOKEN = ''

src/collectorapp/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# CUSTOM DJANGO APPLICATION CONFIGS VARIABLES
1010
APP_ENV = os.environ.get("APP_ENV")
1111
APP_URL = os.environ.get("APP_URL")
12-
12+
PDF_URL = os.environ.get("PDF_URL")
1313

1414
# REDIS
1515
REDIS_HOST = os.environ.get('REDIS_HOST')

src/posts/views.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,10 @@ def view_pdf(request, id):
144144

145145

146146
async def download_pdf(request, id):
147-
# get view_pdf path => /pdf/view/1221554458
148-
# path = reverse('view_pdf', args=(id,))
149-
# pdf = pdfkit.from_url(f'{settings.APP_URL}{path}')
150-
# response = HttpResponse(pdf, content_type='application/pdf')
151-
# response['Content-Disposition'] = f'attachment; filename="{str(id)}.pdf"'
152-
# return response
153-
154-
browser = await launch(options={'args': ['--no-sandbox']}, handleSIGINT=False, handleSIGTERM=False, handleSIGHUP=False)
147+
browser = await launch(options={'ignoreHTTPSErrors':True,'args': ['--no-sandbox']}, handleSIGINT=False, handleSIGTERM=False, handleSIGHUP=False)
155148
page = await browser.newPage()
156149
path = reverse('view_pdf', args=(id,))
157-
await page.goto(f'{settings.APP_URL}{path}')
150+
await page.goto(f'{settings.PDF_URL}{path}')
158151
pdf = await page.pdf({"format": 'A4'})
159152
await browser.close()
160153
response = HttpResponse(pdf, content_type='application/pdf')

0 commit comments

Comments
 (0)