Click here to Skip to main content
15,170,331 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I scraped Dates from a website. I got dates in different formats like some dates are "Dec 4, 2021" and some dates are in "Dec 4,  2021". I used logic to get the updated date and I also made different date formats too and by using Django I show those dates in an HTML table.But the problem is that it shows only "Dec 5, 2021" but not "Dec 5,  2021". I did every possiblity but it couldn't work.


What I have tried:

<pre lang="Python">
now = datetime.datetime.today()
today_date1=now.strftime("%b %d,  %Y")

ab={'date':today_date1}
return render(request, "index.html",ab)

# HTML template

<pre><table>
  <td>{{date}}</td>
</table>


# OUTPUT
Dec 5, 2021 (" its a wrong output. I need two spaces before 2021)
Posted
Updated 5-Dec-21 1:51am

1 solution

There are two spaces: the problem is that multiple whitespace is compressed to single by the HTML renderer:
. Ten spaces here!
.          Ten non-blank spaces here!
In ordeg to "preserve" the multiple spaces, you need to replace "real" spaces with &nbsp; characters.
How whitespace is handled by HTML, CSS, and in the DOM - Web APIs | MDN[^]
   
Comments
Zohair Ahmed 2021 5-Dec-21 7:35am
   
So does "npsb" work in python??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900