Common Challenges Encountered when Developing My Django Blog Site

Simplifying Django Part Two

ยท

4 min read

Introduction ๐Ÿ“–

I made my blog template in this article and then followed the Django Girls tutorial step by step at https://tutorial.djangogirls.org/en/django/. I used it to create my blog site at https://joanitan.pythonanywhere.com/. I recommend you do the same if you want to make a cool Django blog site, just like mine or even better. When you're done, you'll feel proud and accomplished because you built something new. I liked how well the tutorial explained everything, from objects to models, HTML, CSS, and more. Check it out ๐Ÿ˜Š!

In this article, I'll be sharing some common errors I've encountered. Remember, failures are a crucial part of learning, and what I've realized is that errors actually make you a better programmer or developer. So, I would encourage you to embrace them, just as I have, because the results are definitely worth it in the long run. But let's not dwell on that; let me share my errors here. Hopefully, if you come across a similar issue, you won't have to spend as much time fixing it as I did in some cases.

Error Message "python: can't open file 'manage.py': [Errno 2] No such file or directory" ๐Ÿ

When I tried to run the server, I encountered this error, particularly when I had just opened the folder in my code editor and attempted to start the server in the terminal.

Solution ๐Ÿ› ๏ธ

In the error mentioned above, the 'manage.py' file I was attempting to run couldn't be found. To resolve this, I simply navigated to the 'Website' folder, where the 'manage.py' file was located. Hence run the command cd Website

Error Message "ModuleNotFoundError: No module named 'django' " ๐Ÿงฉ

I encountered this error despite having installed Django.

Solution ๐Ÿงฐ

The solution was to activate my virtual environment, where Django was installed, by running the command source myenv/bin/activate

Please note that since I'm using a Linux operating system, the method for activating the virtual environment may vary on other platforms.

Error message " Error:bash: my_env/bin/activate: No such file or directory" ๐Ÿ’ป

This error occurred because the 'my_env' file couldn't be found.

Solution ๐Ÿ› ๏ธ

The solution was to locate my virtual environment file. I had two options: either navigate to the parent directory or move the 'my_env' file to the 'Website' folder. For simplicity, I chose to move the 'my_env' file to the 'Website' folder, aligning it with my 'manage.py' file. This resulted in the following directory structure:

Dango CSS Not Displayed ๐Ÿ–Œ๏ธ

The main challenge I encountered was deploying the site from my local computer to the PythonAnywhere platform, primarily due to issues with CSS loading.

Solution ๐Ÿงฐ

I found the solution by referring to the article at https://help.pythonanywhere.com/pages/DjangoStaticFiles. It turned out that my static file URL was incorrect, so I corrected it. You can see the correct static file URL in the image below

Other Error messages

Many of the other error messages I encountered were a result of not closely following the tutorial. This included occasional misspellings, missing strings in URLs, or forgetting a trailing slash in the static file configuration. For instance, I once typed STATIC_URL = 'static/' instead of STATIC_URL = '/static/', excluding a crucial slash. These errors can be both frustrating and amusing, as they often come from small typos. The other thing is that discovering the source of the problem can even lead to a good laugh, especially when it turns out to be such a minor issue causing significant trouble. Furthermore, the tutorial pointed out certain errors that you might encounter if you followed it, and it also provided documented solutions for these issues.

Conclusion ๐Ÿ“

My main takeaways are as follows:

  1. To avoid errors, always ensure your working directory contains the manage.py file.

  2. Keep the virtual environment activated when running commands.

  3. Follow the tutorial steps carefully.

  4. CSS deployment on PythonAnywhere can be tricky, but there's a supportive community that has likely encountered similar issues and can provide solutions. Don't hesitate to seek their assistance.

Happy coding, fellow Django Dev! ๐Ÿš€

ย