Wednesday, February 2, 2022

Django cache template

How do I not allow Django to cache template, data doesn't change until several refresh have used @never_cache and cache_control doing everything well but still not working

On Tue, Feb 1, 2022, 08:59 Mariusz Felisiak <felisiak.mariusz@gmail.com> wrote:

Details are available on the Django project weblog:

https://www.djangoproject.com/weblog/2022/feb/01/security-releases/

--
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 on the web visit https://groups.google.com/d/msgid/django-users/4f6f73a3-1066-8081-3950-fe0aa7634d11%40gmail.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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAD9bWYx8QVCapZYE4VZRhawMiRS6mF4i8ejg_B2ChqoCLqR1rQ%40mail.gmail.com.

Re: web page blank

Is it working fine for you?


If not url blog/home.html?

On Wed, Feb 2, 2022, 08:08 Sebastian Jung <sebastian.jung2@gmail.com> wrote:
Hello,

Please try:

context = {
        'posts': post
    }

'Delvin Alexander' via Django users <django-users@googlegroups.com> 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:
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    {% for post in posts %}
        <h1>{{ post.title }}</h1>
        <p>By {{ post.author }} on {{ post.date_posted}}</p>
        <p>{{ post.content }}</p>
    {% endfor %}

</body>
</html>

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+unsubscribe@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+unsubscribe@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.

--
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 on the web visit https://groups.google.com/d/msgid/django-users/CAD9bWYzcLeS5HbKQvpa3v%3Drt015_Pufd8BVMe7R_U0OaGZO09g%40mail.gmail.com.

Re: Resource leaks from FieldFile's implicit open?

I think that the documentation is not entirely clear. I wouldn't say that the object "wrapped by" FieldFile is "a wrapper around the result of" Storage.open(). It is actually FieldFile.open() that is a wrapper around Storage.open(). Therefore I think I'd rephrase as follows:

FieldFile is a subclass of File. While File is a wrapper around Python's built-in file object, FieldFile uses the underlying Storage.

As far as I can see by reading the code, you can write code like this:

with some_file_field:
    ...

Inside the "with" block you will probably access `some_file_field.file`. Apparently accessing that attribute is what opens the file (but accessing the `size` attribute also seems to be opening it, which is probably suboptimal.)

I'm not certain about files that don't exist. You might want to wrap the "with" block in a try-except, but I'm not certain about which exceptions you want to catch. It's probably ValueError and IOError.

Regards,

Antonis

Antonis Christofides  +30-6979924665 (mobile)

On 01/02/2022 21.22, Carsten Fuchs wrote:
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    

Tuesday, February 1, 2022

Re: web page blank

Hello,

Please try:

context = {
        'posts': post
    }

'Delvin Alexander' via Django users <django-users@googlegroups.com> 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:
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    {% for post in posts %}
        <h1>{{ post.title }}</h1>
        <p>By {{ post.author }} on {{ post.date_posted}}</p>
        <p>{{ post.content }}</p>
    {% endfor %}

</body>
</html>

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+unsubscribe@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+unsubscribe@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.

Hi,

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 <bharathjinka09@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 <a href="{{pdf_url}}"  download target="__blank" />

All the best

On Wed, Feb 2, 2022 at 11:03 AM ramsha azhar <ramshaazhar12@gmail.com> 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 <ramshaazhar12@gmail.com> 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 <abubakarbryar@gmail.com> wrote:
have you set up the static files in settings.py ?

On Mon, Jan 31, 2022 at 8:49 PM ramsha azhar <ramshaazhar12@gmail.com> 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 <abubakarbryar@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 <ramshaazhar12@gmail.com> wrote:
So guide me the write way ... 

On Mon, 31 Jan 2022, 7:45 pm DJANGO DEVELOPER, <abubakarbryar@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 <ramshaazhar12@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
<img src="/Image_display/" alt="" class="img">
<img src="/Image_display/" alt="" class="img">
<img src="/Image_display/" alt="" class="img">
<img src="/Image_display/" alt="" class="img">

--
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 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+unsubscribe@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+unsubscribe@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+unsubscribe@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 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 on the web visit https://groups.google.com/d/msgid/django-users/CAMyb2%3Dh18EtBixgvyLF2wn-eLNA-uvwejxszEMeu9-kqyVL5xQ%40mail.gmail.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/S4l1OLh5ZPY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKPY9pmoTLTnt_5i%3DNeWtRSSS1BjfyVZ%2BL%3DCSALwnOnZwu6zGw%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMyb2%3DjGOOOYMuJHXDUOMV6sVtCDtkgtjP2OMDaiZjDGrKHBRA%40mail.gmail.com.


--
Thanks and Regards

J. Ranga Bharath
cell: 9110334114


--
Thanks and Regards

J. Ranga Bharath
cell: 9110334114

--
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 on the web visit https://groups.google.com/d/msgid/django-users/CAK5m315kAa3SZxvoyR7eWMYsP3GHrTa3WVap0aeEaQ7jKENNEA%40mail.gmail.com.

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

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 <a href="{{pdf_url}}"  download target="__blank" />

All the best

On Wed, Feb 2, 2022 at 11:03 AM ramsha azhar <ramshaazhar12@gmail.com> 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 <ramshaazhar12@gmail.com> 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 <abubakarbryar@gmail.com> wrote:
have you set up the static files in settings.py ?

On Mon, Jan 31, 2022 at 8:49 PM ramsha azhar <ramshaazhar12@gmail.com> 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 <abubakarbryar@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 <ramshaazhar12@gmail.com> wrote:
So guide me the write way ... 

On Mon, 31 Jan 2022, 7:45 pm DJANGO DEVELOPER, <abubakarbryar@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 <ramshaazhar12@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
<img src="/Image_display/" alt="" class="img">
<img src="/Image_display/" alt="" class="img">
<img src="/Image_display/" alt="" class="img">
<img src="/Image_display/" alt="" class="img">

--
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 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+unsubscribe@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+unsubscribe@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+unsubscribe@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 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 on the web visit https://groups.google.com/d/msgid/django-users/CAMyb2%3Dh18EtBixgvyLF2wn-eLNA-uvwejxszEMeu9-kqyVL5xQ%40mail.gmail.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/S4l1OLh5ZPY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKPY9pmoTLTnt_5i%3DNeWtRSSS1BjfyVZ%2BL%3DCSALwnOnZwu6zGw%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMyb2%3DjGOOOYMuJHXDUOMV6sVtCDtkgtjP2OMDaiZjDGrKHBRA%40mail.gmail.com.


--
Thanks and Regards

J. Ranga Bharath
cell: 9110334114

--
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 on the web visit https://groups.google.com/d/msgid/django-users/CAK5m314q_d4qZdun4znuUp-6N0PG_%3DGPiyWg_wpVjTk4n8AkUg%40mail.gmail.com.

web page blank

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:
<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    {% for post in posts %}
        <h1>{{ post.title }}</h1>
        <p>By {{ post.author }} on {{ post.date_posted}}</p>
        <p>{{ post.content }}</p>
    {% endfor %}

</body>
</html>

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+unsubscribe@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.