10👍
PEP 8, nothing more to say.
Of course you can use your own style (I use camelCase, for example), but most people use recommendations from that PEP.
- What is the difference between south migrations and django migrations?
- Annotate django query if filtered row exists in second table
- Django – How to send a success message using a UpdateView CBV
2👍
Code Complete (http://www.cc2e.com/) has some great chapters about function/variable naming, not for Python explicitly, but perhaps still interesting…
2👍
In addition to the correct references to PEP-8 and Django, let me add Google’s Python style guide, which features a naming convention. It is here.
- Django 1.9: ProgrammingError: relation "users_user" does not exist
- How to create serializer for an enum field in django rest framework
- Can I detect if my code is running on cPython or Jython?
1👍
The important thing is being consistent with your naming style. Choose one with your project mates and use it. Don’t mix them. I personally use camelCase:
Sample class name: MyClass (capital letter at the beginning)
Sample method name: myMethod
Sample variable name: myVariable
Sample constant/enum name: MY_CONST
Class name should start with capital letter to make clear what it is in your code. Same about constants/enums. Values that don’t change throughout your program should consist of capital letters.
1👍
I use lower_case_with_underscore
for variables, methods and functions. I think it really improves readability of the code.
For classes, I tend to use upper case the first letter: class NewsForm (forms.Form):
- Django – CSRF token missing or incorrect
- How to use Django variable in JavaScript file?
- How to install pygments on Ubuntu?
- Django pass variable into template