ᴏʟᴇɢ
Hi. I ran into a little problem while setting up the timezone in Django with PostgreSQL. I have a model with the "auto now add" DateTime field. Data is added 3 hours earlier. Django=3+ PostgreSQL=14 in settings.py I have TIMEZONE = "Europe/Moscow" USE_TZ = True in postgres.config timezone = "Europe/Moscow" timezone_log = "Europe/Moscow" And I altered this timezone to the database user ALTER USER dbms set TimeZone to 'Europe/Moscow'; $psql_ select * from now(); 2021-11-04 17:14:16.673291+03 $_ date Thu 4 Nov 17:14:56 MSK 2021 if now I create objects with django in database. I see 2021-11-04 14:14:16.673291+03 Please tell me what I need to configure so that the date is normal - 17:14:16
voiceless
I have a question I can't understand after high search... How to stored jwt (access, refresh) token in cookies onlyHttp?
Geralt
is there any naming convention when doing django-admin startproject
H i r A
Hi It's all my codes on the model page and class Post is works right but class Points no. When I want to save score, it gives me error. Can you tell me where is my problem?
H i r A
https://nekobin.com/vemepunugo can you help me now?
Vaibhav
https://nekobin.com/vemepunugo can you help me now?
Have u created and applied migration?
Maxim
https://nekobin.com/vemepunugo can you help me now?
no indentation at all Indentation in Python is an important part of the syntax code without indentation is not only impossible to read, it cannot work at all
H i r A
Arash
Hi. I wanted a tip from you. Thank you for your help ... Is it possible to add a product to the cart and create the cart itself on the frontend or not? Or should the view be written on the other side of Django so that Frontend can show these?
Олег
to make a spa, do I need to make an api in Django and access it using js? is there another way?
Hussein
How to get browser id ?
Anonymous
Hi is there any filter for template tag that we want to show a month in Gregorian format? Because by default is another lang and I don't want to change it in my setting. Instead of نوفنمبر I want to show Nov in my template.
Anonymous
Hello
Anonymous
Detected path traversal attempt in '/home/leyla/deployment/media/photos/asics/2021/11/04/c5a98e62452e9a0e38fae.webp'
Anonymous
image_path = os.path.abspath(settings.MEDIA_ROOT + '/photos/asics/' + date.today().strftime('%Y/%m/%d/'))
Anonymous
what is my bad?
Anonymous
def rename_file(instance, filename): if filename.find('.') >= 0: dot_index = (len(filename) - filename.rfind('.', 1)) * (-1) filename = filename[0:dot_index] filename = '{}.{}'.format(filename, 'webp') return os.path.join(image_path, filename)
Anonymous
this code transform my file for jpg to webm
Ismael
what is my bad?
https://forum.djangoproject.com/t/django-3-2-4-update-suspiciousfileoperation-detected-path-traversal-attempt/8196/3
Ismael
check this
Anonymous
I tried, I didn't succeed
マクスイム • グセブ
Detected path traversal attempt in '/home/leyla/deployment/media/photos/asics/2021/11/04/c5a98e62452e9a0e38fae.webp'
The error is somewhat expected, when you call instance.file.save the filename must be relative to MEDIA_ROOT/upload_to.
マクスイム • グセブ
Idk I haven't faced this error yet but maybe it occurs because of an incorrect file path you pass to upload_to destination of model's filefield. That may explain everything
マクスイム • グセブ
Hi is there any filter for template tag that we want to show a month in Gregorian format? Because by default is another lang and I don't want to change it in my setting. Instead of نوفنمبر I want to show Nov in my template.
I think JavaScript can help you 🙂 This toLocaleDateString method is quite handy https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString
マクスイム • グセブ
Yes I know but I don't want to use js
Sometimes you have to use something awful to create something beautiful, right? Don't be afraid to use it)
Brayton
Good night group, could someone help me with a question I have?
Tanner
Yes I know but I don't want to use js
Chances are you’ll have to use some js at some point in your projects! It’s not awful, it’s essential! If you really want a template tag, you can swiftly write a custom one https://docs.djangoproject.com/en/3.2/howto/custom-template-tags/. You could create an enum class with all the months hard coded and render the Gregorian month accordingly!
Bakhodir
hi every body, how can I check password hash which generated with Yii2 framework on django?
enansi
Hi everyone, I'm doing a basic demo project, its a messaging application. So I have the models Group , Message , User ... I want to track Read/Unread messages, so I have a MessageRead (time_read, message_id, user_id) model... is there a better way to track read messages other than doing an entire model?
enansi
You can add time_read field and one more field 'read' as a boolean field In message model right?
Yes, but messages sent to a "Group" will have more than one recipient. So my purpose for "read messages" is actually showing: For UserX, how many messages are read or unread in the GroupY.
Vaibhav
How would that look?
Just write down ur functional requirements like what all. need to know and track and use message as an fk
Жоомарт
Hello, I made a parser that works with Django and saves data to the database, but I also need to add something like a button to the Django admin panel for parsing, does anyone know how to implement this?
Sunken
Hi everyone Is there any body can help me with this error? Could not install package due to an OSError: No such file or directory:... It is relate to run "git push heroku master" I'd tried every solution I have found
Eric
How can i use SQLAlchemy in django, can anyone help me
The two ORMs Django's built-in ORM and sqlalchemy have a lot of overlap. Just use the Django ORM
Eric
Hello, I have an English website built with Django, is there any way to make it in another language? Like translate it or something
Use https://github.com/WeblateOrg/weblate or https://github.com/deschler/django-modeltranslation
Hussein
Hallo, How to get browser id ?
Doragonsureiyā
Hallo, How to get browser id ?
What are you talking about?
ADI
How we can get two models fields data one model frentend Plese explain it
Eric
Hallo, How to get browser id ?
If you mean "Get the User Agent of the browser that makes a request?" then you just access the META attribute of the request object: request.META['HTTP_USER_AGENT']
ADI
How can I display two model data in django ? Freinds
Hussein
I want to save the browser id in the user's database so that he can not log in from another place later
Anonymous
How can i use SQLAlchemy in django, can anyone help me
I guess you are using existing lagacy DB. You can use 'inspectdb' to get all table in that database & u can use django ORM
Ashish
I deployed django app in heroku but static files and images not working help me?
Ashish
Yes
Ashish
Change debug false and allow host
Roberto
Hello all, I want to render a symbol in svg format inside a class-based listview template. I found django-inline-svg which let use the {%svg 'file_name' %} template tag to render the file_name.svg. I was trying to do something like: {% for sign in article.signs.all %} {% svg '{{sign.name}}_symbol' %} {% endfor %} but of course it doesn't work. Would you please suggest me a way to do it?
Dominik
Hi guys, I ran into this error and can’t understand why it happens django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. *Note everything in the project is working and I can start testserver normally. It just happens when I’m trying to run my models.py code for testing.
Dominik
What command did you use to run the models.py ?
I ran it in pycharm with control + r Do I have to run it differently when the script is inside a django app? For testing.
cj
are you using pytest or Django's TestCase?
Dominik
what do you mean by "trying to run my models.py code for testing." you don't need to run models.py for testing, can you show your test cases code?
I read that it is common to put business logic into your models —> FAT models Thin views and I was putting in some logic which I wanted to test.
Dominik
It should not be a usual TestCase. It is just to look if my script is working fine.
cj
It should not be a usual TestCase. It is just to look if my script is working fine.
but ... you're writing your tests in a test.py file, right? almost everything should be a usual TestCase or a pytest function ¯\_(ツ)_/¯ how are you testing your code then?
マクスイム • グセブ
I read that it is common to put business logic into your models —> FAT models Thin views and I was putting in some logic which I wanted to test.
Any manipulation with models should take place only after Django was set up. This can be done by calling django.setup() Here's more about this function: https://docs.djangoproject.com/en/2.2/topics/settings/#calling-django-setup-is-required-for-standalone-django-usage Also, to check a validity of your models code you may want to use Django unit tests (that's what @c0x6a is talking about). Tests are cool. (models.py file can't be run independently, that's the gist)
N
I have a problem. In the input, of course, the input field is affiliated with the crditcard library in Dijango. I am required to register in it 11/23 If you register something other than that, for example. number. 55/44. or letters. I get an error on the whole site, how do I solve this problem for me for a month
Anonymous
What it means: user = request.user, so I have not imported request, neither user. How django find my users?