Home > Enterprise >  Would this make my code faster? Should I not follow Django's structure best practices and would
Would this make my code faster? Should I not follow Django's structure best practices and would

Time:07-15

I don't know what makes my code fast or slow... is it the quantity of lines? How separated between different files it is? What I am trying to do?

On a Django website could my website security be compromised because of me not following Django's project structure best practices? (if that would give my code more speed)

How could I make my Django website as fast as possible without compromising security?

CodePudding user response:

Hye,

  1. Clean Code -> always try to make your code asap -> as simple as possible. as cleaner your code will be, as clear its logic will be.
  2. Queryset -> Think of your querysets correctly, In django Querysets are lazy, and sometimes you also just need to check like row just exists or not. Make least Joins with large tables. Usually Queries are optimized, but its machine written so you never know, if it becomes hard to run.
  3. Security wise - Django is very very secure. If you read this article https://docs.djangoproject.com/en/4.0/topics/security/ , this says that you are getting security is many ways.
  4. Naming - This will be helpful in development persepective, A good code is said to be self explanatory, When we learn code, we loop with i and j but in real world, you loop on real things, like "for page is pages", will be more readable than "for i in pages".
  5. Permissions and Grouping - Like AWS has permissions based architecture, if you are creating something big, you will need these. See not every user can do everything. We assign permissions to Marketing, then internal company user, external users, maybe clients or stockholders too.
  6. Good Urls and following RFC rules, will help you more and more. Its like art, the more you see, the more you improve, LIkes Urls, views naming application namings
  7. You can learn some basic but advanced features like pagination or infinte scrolling is one of the good features you can use. There are way to many ways to increase your capabilities you can read more on this article.https://django-best-practices.readthedocs.io/en/latest/.

Happy Coding.

  • Related