These are chat archives for django/django
when i enter this url
http://localhost:8000/category/bedroom-items/almirah/2-piece-almirah whose route is configured as following
url(r'^category/(?P<hierarchy>.+)/', views.show_product_on_category, name='product-category'),
then in views
def show_product_on_category(request, hierarchy=None): print('hierarchy', hierarchy) # this prints hierarchy bedroom-items/almirah
Does not this should print hierarchy bedroom-items/almirah/2-piece-almirah?
why removing / like the following
then prints the
hierarchy bedroom-items/almirah/2-piece-almirah. I am very curios to understand why this works and not the other?
class Person(models.Model): # Create relationship (don't inherit from User!) user = models.OneToOneField(User) nickname = models.CharField(max_length=42)
AttributeError: 'User' object has no attribute 'Person'
AttributeError: 'User' object has no attribute 'nickname'
when trying in my view
person = request.user print(person.nickname)
person = request.user.Person print(person)
@LukeVideo In order to use
reverse relation. You are almost there. Use this
Let me define reverse relation in this way
user = models.OneToOneField(User, related_name='person')
Explicitly define the keyword is prefered here for sake of clarity
person = requuest.user.person nickname = person.nickname
But in short you can simply write
Do not be afraid to has long dot. It works. Normally
import pdb; pdb.set_trace() I suggest next time on this issue try
pdb It will save your time a lot.
frontendengineer convert the filename before POST them to me already(IMO)
utf8and space in
utf8. I don't believe Django rejects it
with open(document, 'rb') as afile: FileNotFoundError: [Errno 2] No such file or directory: "/home/lukevideo/.../media/documents/Capture d'écran de 2017-11-17 11-24-59.png"
Capture\ d'écran\ de\ 2017-11-17 11-24-59.png
GNU/Linux Debian StretchDjango2 Python3.6.3 can upload your file