Re: web page blank

2022-02-01 Thread Sebastian Jung
Hello,

Please try:

context = {
'posts': post
}

'Delvin Alexander' via Django users  schrieb
am Mi., 2. Feb. 2022, 06:59:

> Hello everyone,
>
> I am currently following a django tutorial regarding applications. I have
> followed through completely but for some reason, when I run server, i incur
> no errors but the web page is blank. Why would this be?
>
> Here is what is not displayed:
>
> from my Home.html file:
> 
> 
> 
> 
> 
> 
> {% for post in posts %}
> {{ post.title }}
> By {{ post.author }} on {{ post.date_posted}}
> {{ post.content }}
> {% endfor %}
>
> 
> 
>
> from my views.py file:
> from django.shortcuts import render
>
> post = [
> {
> 'author': 'CoreyMS',
> 'title': 'Blog Post',
> 'content': 'First Post Content',
> 'date_posted': 'August 27, 2018'
> },
> {
> 'author': 'Jane Doe',
> 'title': 'Blog Post 2',
> 'content': 'Second Post Content',
> 'date_posted': 'August 28, 2018'
> }
> ]
>
> def home(request):
> context = {
> 'post': post
> }
> return render(request, 'blog/home.html', context)
>
> def about(request):
> return render(request, 'blog/about.html')
>
> My urls.py:
> from django.urls import path
> from . import views
>
> urlpatterns = [
> path('', views.home, name='blog-home'),
> path('about/', views.about, name='blog-about'),
> ]
>
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e9b557a6-403b-46ce-bc18-8d19b0091f2an%40googlegroups.com
> 
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKGT9mzFaC4Eq9B_76nb0N2%2BRW-%2BNkbLMdfJT0Vph2qWuGefOw%40mail.gmail.com.


Re: how to Display images other than from static folder.

2022-02-01 Thread RANGA BHARATH JINKA
Hi,

Please follow this.
https://djangocentral.com/managing-media-files-in-django/
You have to store your images in a static media folder by adding the media
path in settings.py.
This is the recommended way and easy to access the images

All the best

On Wed, Feb 2, 2022 at 11:30 AM RANGA BHARATH JINKA <
bharathjink...@gmail.com> wrote:

> Hi,
>
> Pass the pdf URL as a context variable in the views function. Then you can
> easily access it in your HTML using jinja templating and HTML anchor tag  href="{{pdf_url}}"  download target="__blank" />
>
> All the best
>
> On Wed, Feb 2, 2022 at 11:03 AM ramsha azhar 
> wrote:
>
>> still, I'm confused, Guide me what to write in views.py to display images
>> on my HTML page.
>> the main problem is how to set this path in views.py file to get image
>> from this path. I jst want to display this tree.pdf file on my html page.
>> Any one tell me what to write in views.py?
>> BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
>> filename = 'Tree.pdf'
>> filepath = BASE_DIR + '//' + filename
>> path = open(filepath, 'rb')
>>
>> On Mon, Jan 31, 2022 at 9:00 PM ramsha azhar 
>> wrote:
>>
>>> yes, I set check the attached settings.py file
>>>  just want to know In template page how I set the path od
>>> back directory folder where tree.png is placed.
>>>
>>> On Mon, Jan 31, 2022 at 8:55 PM DJANGO DEVELOPER <
>>> abubakarbr...@gmail.com> wrote:
>>>
 have you set up the static files in settings.py ?

 On Mon, Jan 31, 2022 at 8:49 PM ramsha azhar 
 wrote:

> I just want to display the attached Tree.png image on the HTML page
> but this image is created each time new according to the user input file.
> guide me how to set the path of this mage on an HTML page or how to 
> display
> this tree.png as a user output image.
>
> On Mon, Jan 31, 2022 at 8:36 PM DJANGO DEVELOPER <
> abubakarbr...@gmail.com> wrote:
>
>> tell me what you want to get as a result? do you want to display
>> multiple images on HTML template?
>>
>> On Mon, Jan 31, 2022 at 8:27 PM ramsha azhar 
>> wrote:
>>
>>> So guide me the write way ...
>>>
>>> On Mon, 31 Jan 2022, 7:45 pm DJANGO DEVELOPER, <
>>> abubakarbr...@gmail.com> wrote:
>>>
 you are doing it the wrong way. totally the wrong way. I am not
 being rude.

 On Mon, Jan 31, 2022 at 7:42 PM ramsha azhar <
 ramshaazha...@gmail.com> wrote:

> Gide me Django develpers. I just want to display my pictures that
> are created each time new.
> My mages are created in my project folder, not in the static
> folder.
> how I display images on the HTML page by using the path of my
> project folder.
>
> views.py
>
> def Image_display(request):
>   BASE_DIR =
> os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
>   filename = 'Tree.jpg'
>   filepath = BASE_DIR + '//' + filename
>   images = Image.objects.all('filepath')
>   return render(request, "xyz.html", {'images': images})
>
> url.py
> path('Image_display/', views.Image_display, name="Image_display"),
>
> HTML page
> 
> 
> 
> 
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8da245ea-ea90-4730-83c0-accafc93b86bn%40googlegroups.com
> 
> .
>
 --
 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+unsubscr...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/CAKPY9p%3DE1FmUc%3Dqqy1tGYBJbimFX873XXSTDndnn4kVUjo3ZWg%40mail.gmail.com
 
 .

>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> 

Re: how to Display images other than from static folder.

2022-02-01 Thread RANGA BHARATH JINKA
Hi,

Pass the pdf URL as a context variable in the views function. Then you can
easily access it in your HTML using jinja templating and HTML anchor tag 

All the best

On Wed, Feb 2, 2022 at 11:03 AM ramsha azhar 
wrote:

> still, I'm confused, Guide me what to write in views.py to display images
> on my HTML page.
> the main problem is how to set this path in views.py file to get image
> from this path. I jst want to display this tree.pdf file on my html page.
> Any one tell me what to write in views.py?
> BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
> filename = 'Tree.pdf'
> filepath = BASE_DIR + '//' + filename
> path = open(filepath, 'rb')
>
> On Mon, Jan 31, 2022 at 9:00 PM ramsha azhar 
> wrote:
>
>> yes, I set check the attached settings.py file
>>  just want to know In template page how I set the path od
>> back directory folder where tree.png is placed.
>>
>> On Mon, Jan 31, 2022 at 8:55 PM DJANGO DEVELOPER 
>> wrote:
>>
>>> have you set up the static files in settings.py ?
>>>
>>> On Mon, Jan 31, 2022 at 8:49 PM ramsha azhar 
>>> wrote:
>>>
 I just want to display the attached Tree.png image on the HTML page but
 this image is created each time new according to the user input file. guide
 me how to set the path of this mage on an HTML page or how to display this
 tree.png as a user output image.

 On Mon, Jan 31, 2022 at 8:36 PM DJANGO DEVELOPER <
 abubakarbr...@gmail.com> wrote:

> tell me what you want to get as a result? do you want to display
> multiple images on HTML template?
>
> On Mon, Jan 31, 2022 at 8:27 PM ramsha azhar 
> wrote:
>
>> So guide me the write way ...
>>
>> On Mon, 31 Jan 2022, 7:45 pm DJANGO DEVELOPER, <
>> abubakarbr...@gmail.com> wrote:
>>
>>> you are doing it the wrong way. totally the wrong way. I am not
>>> being rude.
>>>
>>> On Mon, Jan 31, 2022 at 7:42 PM ramsha azhar <
>>> ramshaazha...@gmail.com> wrote:
>>>
 Gide me Django develpers. I just want to display my pictures that
 are created each time new.
 My mages are created in my project folder, not in the static folder.
 how I display images on the HTML page by using the path of my
 project folder.

 views.py

 def Image_display(request):
   BASE_DIR =
 os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
   filename = 'Tree.jpg'
   filepath = BASE_DIR + '//' + filename
   images = Image.objects.all('filepath')
   return render(request, "xyz.html", {'images': images})

 url.py
 path('Image_display/', views.Image_display, name="Image_display"),

 HTML page
 
 
 
 

 --
 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+unsubscr...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/8da245ea-ea90-4730-83c0-accafc93b86bn%40googlegroups.com
 
 .

>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAKPY9p%3DE1FmUc%3Dqqy1tGYBJbimFX873XXSTDndnn4kVUjo3ZWg%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAMyb2%3DheLgJo5dMxsCgQ8cm%3Dp0px5EHpLr2frYtDowV8mmC%2BbQ%40mail.gmail.com
>> 
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> 

web page blank

2022-02-01 Thread 'Delvin Alexander' via Django users
Hello everyone,

I am currently following a django tutorial regarding applications. I have 
followed through completely but for some reason, when I run server, i incur 
no errors but the web page is blank. Why would this be?

Here is what is not displayed:

from my Home.html file:






{% for post in posts %}
{{ post.title }}
By {{ post.author }} on {{ post.date_posted}}
{{ post.content }}
{% endfor %}




from my views.py file:
from django.shortcuts import render

post = [
{
'author': 'CoreyMS',
'title': 'Blog Post',
'content': 'First Post Content',
'date_posted': 'August 27, 2018'
},
{
'author': 'Jane Doe',
'title': 'Blog Post 2',
'content': 'Second Post Content',
'date_posted': 'August 28, 2018'
}
]

def home(request):
context = {
'post': post
}
return render(request, 'blog/home.html', context)

def about(request):
return render(request, 'blog/about.html')

My urls.py:
from django.urls import path
from . import views

urlpatterns = [
path('', views.home, name='blog-home'),
path('about/', views.about, name='blog-about'),
]
  

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e9b557a6-403b-46ce-bc18-8d19b0091f2an%40googlegroups.com.


Re: how to Display images other than from static folder.

2022-02-01 Thread ramsha azhar
still, I'm confused, Guide me what to write in views.py to display images
on my HTML page.
the main problem is how to set this path in views.py file to get image from
this path. I jst want to display this tree.pdf file on my html page.
Any one tell me what to write in views.py?
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
filename = 'Tree.pdf'
filepath = BASE_DIR + '//' + filename
path = open(filepath, 'rb')

On Mon, Jan 31, 2022 at 9:00 PM ramsha azhar 
wrote:

> yes, I set check the attached settings.py file
>  just want to know In template page how I set the path od
> back directory folder where tree.png is placed.
>
> On Mon, Jan 31, 2022 at 8:55 PM DJANGO DEVELOPER 
> wrote:
>
>> have you set up the static files in settings.py ?
>>
>> On Mon, Jan 31, 2022 at 8:49 PM ramsha azhar 
>> wrote:
>>
>>> I just want to display the attached Tree.png image on the HTML page but
>>> this image is created each time new according to the user input file. guide
>>> me how to set the path of this mage on an HTML page or how to display this
>>> tree.png as a user output image.
>>>
>>> On Mon, Jan 31, 2022 at 8:36 PM DJANGO DEVELOPER <
>>> abubakarbr...@gmail.com> wrote:
>>>
 tell me what you want to get as a result? do you want to display
 multiple images on HTML template?

 On Mon, Jan 31, 2022 at 8:27 PM ramsha azhar 
 wrote:

> So guide me the write way ...
>
> On Mon, 31 Jan 2022, 7:45 pm DJANGO DEVELOPER, <
> abubakarbr...@gmail.com> wrote:
>
>> you are doing it the wrong way. totally the wrong way. I am not being
>> rude.
>>
>> On Mon, Jan 31, 2022 at 7:42 PM ramsha azhar 
>> wrote:
>>
>>> Gide me Django develpers. I just want to display my pictures that
>>> are created each time new.
>>> My mages are created in my project folder, not in the static folder.
>>> how I display images on the HTML page by using the path of my
>>> project folder.
>>>
>>> views.py
>>>
>>> def Image_display(request):
>>>   BASE_DIR =
>>> os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
>>>   filename = 'Tree.jpg'
>>>   filepath = BASE_DIR + '//' + filename
>>>   images = Image.objects.all('filepath')
>>>   return render(request, "xyz.html", {'images': images})
>>>
>>> url.py
>>> path('Image_display/', views.Image_display, name="Image_display"),
>>>
>>> HTML page
>>> 
>>> 
>>> 
>>> 
>>>
>>> --
>>> 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+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/8da245ea-ea90-4730-83c0-accafc93b86bn%40googlegroups.com
>>> 
>>> .
>>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAKPY9p%3DE1FmUc%3Dqqy1tGYBJbimFX873XXSTDndnn4kVUjo3ZWg%40mail.gmail.com
>> 
>> .
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAMyb2%3DheLgJo5dMxsCgQ8cm%3Dp0px5EHpLr2frYtDowV8mmC%2BbQ%40mail.gmail.com
> 
> .
>
 --
 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+unsubscr...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/CAKPY9p%3DOofwq7YrTp%3DWoKyO7mgxVovK2wN3-%3Dm9Ed2zTWZ%2BdAg%40mail.gmail.com
 
 .

>>> --
>>> You received this message because you are subscribed to the Google
>>> 

Re: Barcode

2022-02-01 Thread Alen Zuvic
punakap...@gnail.com

On Wed, 2 Feb 2022, 01:08 Alen Zuvic,  wrote:

>
> On Wed, 2 Feb 2022, 01:05 Andres Quilindo, <
> andres.quili...@uaiinpebi-cric.edu.co> wrote:
>
>> Does anyone have experience with UCC/EAN-128 barcodes? I am using a
>> javascript barcode js library with django to implement the barcode but it
>> is generating errors when reading if anyone knows any library or api that
>> can be used that complies with the UCC/EAN-128 parameters that can provide
>> me with information
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/13b745fe-8fef-4017-98eb-e571edee7fedn%40googlegroups.com
>> 
>> .
>>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAABMtpo9FV%2BM3vu9Z9-FAnEyVd2Hb5_YZG5ejxhkj8xdTUcsGA%40mail.gmail.com.


Barcode

2022-02-01 Thread Andres Quilindo
Does anyone have experience with UCC/EAN-128 barcodes? I am using a 
javascript barcode js library with django to implement the barcode but it 
is generating errors when reading if anyone knows any library or api that 
can be used that complies with the UCC/EAN-128 parameters that can provide 
me with information

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/13b745fe-8fef-4017-98eb-e571edee7fedn%40googlegroups.com.


Resource leaks from FieldFile's implicit open?

2022-02-01 Thread Carsten Fuchs
Dear group,

despite a lot of reading and searching I still don't understand how FieldFiles 
work.

The documentation at 
https://docs.djangoproject.com/en/4.0/ref/models/fields/#django.db.models.fields.files.FieldFile
 says:

> The API of FieldFile mirrors that of File, with one key difference: The 
> object wrapped by the class is not necessarily a wrapper around Python’s 
> built-in file object. Instead, it is a wrapper around *** the result of the 
> Storage.open() method ***, which may be a File object, or it may be a custom 
> storage’s implementation of the File API.

(I added markers to indicate the portion that I have trouble with.)

As far as I understand this, whenever a `FieldFile` is instantiated, 
`Storage.open()` is called. Thus, if the underlying storage is the 
`FileSystemStorage`, a Python file object is opened.

However, how is this file handle closed again?

It looks as if it stays open until garbage collected, that is, possibly for a 
very long time.

Another consequence besides the potential resource leak seems to be that the 
implicit open will raise an exception if the file that the `FieldFile` refers 
to doesn't exist. As I don't exactly understand when this opening occurs, a lot 
of code must be wrapped in try-except blocks to handle this?

Best regards,
Carsten

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/eb81a066-4328-4f36-87a2-ead61aba6679%40cafu.de.


Re: Downloading html as pdf using popen, headless chrome option

2022-02-01 Thread Aadil Rashid
*@Jisson Varghese Thank you very much it worked completely fine now*

On Tuesday, February 1, 2022 at 11:39:22 PM UTC+5:30 jis...@gmail.com wrote:

> Check whether FileResponse instead of StreamingHttpResponse helps to solve 
> the issue , 
> https://docs.djangoproject.com/en/4.0/ref/request-response/#fileresponse-objects
>
> On Tue, Feb 1, 2022 at 11:26 PM Aadil Rashid  wrote:
>
>> I am trying to generating pdf from webpages, using popen , but when i 
>> call this
>> view it generates UnicodeDecodeError: 'utf-8' codec can't decode byte 
>> 0xd3 in position 10: invalid continuation byte 
>>
>> This is my view
>> from projName.settings import BASE_DIR
>> from subprocess import Popen, PIPE, STDOUT
>> from wsgiref.util import FileWrapper
>> from django.http import StreamingHttpResponse
>>
>> class DownloadAsPDF(View):
>> def post(self, request, *args, **kwargs): 
>> base = str(BASE_DIR)
>> file_name = str( base + '/testreport.pdf')
>> post_url = request.POST.get("page_url")
>> url = str('http://' + request.get_host() + post_url)
>> chrome_args = ['/path/google-chrome', '--headless', 
>> '--virtual-time-buget=2',
>> '--print-to-pdf=/path/testreport.pdf', url]
>> external_process = Popen(chrome_args, stdout=PIPE, stderr=STDOUT) 
>> external_process.wait()
>> return_file = FileWrapper(open('{}'.format(file_name), 'r'))
>> download_file_name = 'report'
>> response = StreamingHttpResponse(return_file, 
>> content_type='application/force-download')
>> response['Content-Disposition'] = f'attachment; filename= 
>> {download_file_name}.pdf' 
>> return response
>>
>>
>> Can please anybody, tell me why is it generating this error and what is 
>> the possible solution 
>> this problem, Thanks you very much
>>
>> -- 
>> 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...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/9a0b68e5-a587-4ac4-a018-a8fcc18f1cf4n%40googlegroups.com
>>  
>> 
>> .
>>
>
>
> -- 
> *Jisson Varghese*
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4bf19bc2-9d5d-476f-952f-f06a5220036bn%40googlegroups.com.


Re: Downloading html as pdf using popen, headless chrome option

2022-02-01 Thread Jisson Varghese
Check whether FileResponse instead of StreamingHttpResponse helps to solve
the issue ,
https://docs.djangoproject.com/en/4.0/ref/request-response/#fileresponse-objects

On Tue, Feb 1, 2022 at 11:26 PM Aadil Rashid 
wrote:

> I am trying to generating pdf from webpages, using popen , but when i call
> this
> view it generates UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd3
> in position 10: invalid continuation byte
>
> This is my view
> from projName.settings import BASE_DIR
> from subprocess import Popen, PIPE, STDOUT
> from wsgiref.util import FileWrapper
> from django.http import StreamingHttpResponse
>
> class DownloadAsPDF(View):
> def post(self, request, *args, **kwargs):
> base = str(BASE_DIR)
> file_name = str( base + '/testreport.pdf')
> post_url = request.POST.get("page_url")
> url = str('http://' + request.get_host() + post_url)
> chrome_args = ['/path/google-chrome', '--headless',
> '--virtual-time-buget=2',
> '--print-to-pdf=/path/testreport.pdf', url]
> external_process = Popen(chrome_args, stdout=PIPE, stderr=STDOUT)
> external_process.wait()
> return_file = FileWrapper(open('{}'.format(file_name), 'r'))
> download_file_name = 'report'
> response = StreamingHttpResponse(return_file,
> content_type='application/force-download')
> response['Content-Disposition'] = f'attachment; filename=
> {download_file_name}.pdf'
> return response
>
>
> Can please anybody, tell me why is it generating this error and what is
> the possible solution
> this problem, Thanks you very much
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9a0b68e5-a587-4ac4-a018-a8fcc18f1cf4n%40googlegroups.com
> 
> .
>


-- 
*Jisson Varghese*

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAADa5QfL1dmbPFWChRnF8OxowsBaOCAOo2Xq%2Bu-EshjA4LpydA%40mail.gmail.com.


Downloading html as pdf using popen, headless chrome option

2022-02-01 Thread Aadil Rashid
I am trying to generating pdf from webpages, using popen , but when i call 
this
view it generates UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd3 
in position 10: invalid continuation byte 

This is my view
from projName.settings import BASE_DIR
from subprocess import Popen, PIPE, STDOUT
from wsgiref.util import FileWrapper
from django.http import StreamingHttpResponse

class DownloadAsPDF(View):
def post(self, request, *args, **kwargs): 
base = str(BASE_DIR)
file_name = str( base + '/testreport.pdf')
post_url = request.POST.get("page_url")
url = str('http://' + request.get_host() + post_url)
chrome_args = ['/path/google-chrome', '--headless', 
'--virtual-time-buget=2',
'--print-to-pdf=/path/testreport.pdf', url]
external_process = Popen(chrome_args, stdout=PIPE, stderr=STDOUT) 
external_process.wait()
return_file = FileWrapper(open('{}'.format(file_name), 'r'))
download_file_name = 'report'
response = StreamingHttpResponse(return_file, 
content_type='application/force-download')
response['Content-Disposition'] = f'attachment; filename= 
{download_file_name}.pdf' 
return response


Can please anybody, tell me why is it generating this error and what is the 
possible solution 
this problem, Thanks you very much

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9a0b68e5-a587-4ac4-a018-a8fcc18f1cf4n%40googlegroups.com.


Re: TypeError: 'module' object is not iterable - django 4

2022-02-01 Thread muwaga micheal
Issue was sorted..
Here is the link.
python 3.x - TypeError: 'module' object is not iterable in django 4 - Stack 
Overflow 


On Monday, January 31, 2022 at 11:53:03 AM UTC+3 muwaga micheal wrote:

> Hi 
> Team,
>  I am getting the above error, it has persisted long enough than at this 
> point i really need help.
> I am using pickle to load an ML model, POST to get user input. Below is 
> the error, my urls.py file and the views.py file. 
> Any Help will be highly appreciated.
>
> *** Error Message ***
>
> (python10_env) D:\Online 
> Drives\MDigital\CIT-Letures\python10_env\smart_health_consult>python 
> manage.py runserver
> Watching for file changes with StatReloader
> Performing system checks...
>
> Exception in thread django-main-thread:
> Traceback (most recent call last):
>   File "D:\Online 
> Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\urls\resolvers.py",
>  
> line 634, in url_patterns
> iter(patterns)
> TypeError: 'module' object is not iterable
>
> The above exception was the direct cause of the following exception:
>
> Traceback (most recent call last):
>   File 
> "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\threading.py", 
> line 1009, in _bootstrap_inner
> self.run()
>   File 
> "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\threading.py", 
> line 946, in run
> self._target(*self._args, **self._kwargs)
>   File "D:\Online 
> Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\utils\autoreload.py",
>  
> line 64, in wrapper
> fn(*args, **kwargs)
>   File "D:\Online 
> Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\core\management\commands\runserver.py",
>  
> line 124, in inner_run
> self.check(display_num_errors=True)
>   File "D:\Online 
> Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\core\management\base.py",
>  
> line 438, in check
> all_issues = checks.run_checks(
>   File "D:\Online 
> Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\core\checks\registry.py",
>  
> line 77, in run_checks
> new_errors = check(app_configs=app_configs, databases=databases)
>   File "D:\Online 
> Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\core\checks\urls.py",
>  
> line 40, in check_url_namespaces_unique
> all_namespaces = _load_all_namespaces(resolver)
>   File "D:\Online 
> Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\core\checks\urls.py",
>  
> line 67, in _load_all_namespaces
> namespaces.extend(_load_all_namespaces(pattern, current))
>   File "D:\Online 
> Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\core\checks\urls.py",
>  
> line 57, in _load_all_namespaces
> url_patterns = getattr(resolver, 'url_patterns', [])
>   File "D:\Online 
> Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\utils\functional.py",
>  
> line 48, in __get__
> res = instance.__dict__[self.name] = self.func(instance)
>   File "D:\Online 
> Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\urls\resolvers.py",
>  
> line 642, in url_patterns
> raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e
> django.core.exceptions.ImproperlyConfigured: The included URLconf ' 'ml_dp_model.urls' from 'D:\\Online 
> Drives\\MDigital\\CIT-Letures\\python10_env\\smart_health_consult\\ml_dp_model\\urls.py'>'
>  
> does not appear to have any patterns in it. If you see the 'urlpatterns' 
> variable with valid patterns in the file then the issue is probably caused 
> by a circular import.
>
> **
>
>   urls.py  *
> from django.urls import path
> from . import views
>
> #from .views import index
> #from .views import predict
>
> urlpartterns = [
> path('', views.index, name='index'),
> path('result.html', views.predict, name='predict')
> 
> ]
> **
>
> * views.py *
> from django.shortcuts import render
> # Testing if context can solve circular refference issue.
> from django.template import context
> # Model related imports
> import pandas as pd #install pandas
> import pickle
> import numpy as np #  helps to manipulate the data
>
> # Create your views here.
> def index(request):
> return render(request, 'index.html')
>
> # importing the models using pickle.
> #Loading Naive Bayes Pickle  Model load method 1
> nb_pickle = open('./models_store/final_nb_model.pickel','rb+')
> nb_model = pickle.load(nb_pickle)
> #Loading RandomForest Pickle Modal load method 1
> rf_pickle = open('./models_store/final_rf_model.pickel', 'rb+')
> rf_model = pickle.load(rf_pickle)
> #Loading Scala Vector Machine  Pickle  Model load method 2
> svm_model = pickle.load(open('./models_store/final_svm_model.pickel', 
> 'rb+'))
>
> # Disease prediction Function:
> def predict(request):
> if