If you have any questions, comments, or issues with this project please post them here!
Hi Guys,
I am so stuck with this… and even with David’s Solution I cannot figure out, why my blog entries are not showing…
Please, please have a go at my code (you have to set secret key and password first, and some entries).
The db storing works fine but something in my code is messed up, that it won’t view the blog entries.
Please help
This is my repl:
https://replit.com/@surfineer/Day-86-BLOG-WEBSITE?v=1
THANKS SO MUCH FOR ANY ADVICE
As you put in your code
try: #I think this part is not working correctly
new = new.replace("{date}",db[key])
new = new.replace("{title}",db[key]["title"])
new = new.replace("{blogtext}",db[key]["blogtext"])
content += new
it appears that you’re trying to replace {date}
with the entire value associated with key
. However, according to your blog_entry()
function, db[key]
(where key
is date) is a dictionary with title
and blogtext
as keys.
I think you probably meant to replace {date}
with the key itself.
Try updating your view()
to something like:
def view():
keys = list(db.keys())
page= ""
f = open("templates/content.html","r")
page = f.read()
content = ""
for key in reversed(keys):
if key != "password":
new = page
try:
new = new.replace("{date}", key) # Replace with 'key', not 'db[key]'
new = new.replace("{title}", db[key]["title"])
new = new.replace("{blogtext}", db[key]["blogtext"])
content += new
except:
print("it's this")
return content
Yes!!! That was it! Thank You so much!!
No problem! Don’t forget to mark the answer as solved as it can help other people!
I think only admins can do that, as I cannot find a button for it…
Nope. You can mark topics you created as solved and TL4+ can mark other people’s topics. The reason you can’t is because the Solved plugin was disabled for #code-help:100-days-of-code.
hi there,
On day 86 of 100 there task is to create a blog that allows 1 user (one’s self) to log in and then add and view their own posts.
I have added a sign up function which, given I am using the replit DB, mixes the key / values of users.
later I am trying to go to the DB and get all the posts that have a key-value pair “date”:date and this try block does not get executed and goes to the exception which seems to inform me that the key is the issue.
I am aware this is not great code and there are other issues. I am trying to solve this first but would love more feedback overall. Thank you in advance.
To better diagnose the problem, remove try
and except
(but leave the code you want to try). This way, the program will crash with an error message. You can use this error message to better diagnose your problem.
I would add some prints in the try block to understand when the except is triggered (before the if, before the for, before the return)