Jack👨🏻‍💻
hi guys i have small issue with crispy-forms
Jack👨🏻‍💻
my form is auto validating
Jack👨🏻‍💻
how can i avoid it
Jack👨🏻‍💻
please help someone
Anonymous
I"m getting ('NAME':BASE_DIR / 'db.sqlite3' ) unsupported operand type(s) for /: 'str' and 'str' error My BASE_DIR Value : os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Anonymous
How to fix it anyone ?
Anonymous
Installed
Alex
No it's django 3.1.1
ok, then how is BASE_DIR defined?
Anonymous
ok, then how is BASE_DIR defined?
Actually it's default value was : Path(__file__).resolve().parent.parent when i first setup the project But someone suggested me to change it to os.path.join ......
Sergey
Add self in foreign key
yes i know but how to mange depth of such relation? e.g i want number of innerit elemets with same structure not bigger then 5
Alex
Actually it's default value was : Path(__file__).resolve().parent.parent when i first setup the project But someone suggested me to change it to os.path.join ......
the first variant is using the pathlib https://docs.python.org/3/library/pathlib.html the second is os.path https://docs.python.org/3/library/os.path.html That slash syntax BASE_DIR / 'db.sqlite3' is for the pathlib, but you're actually using os.path which doesn't support it.
Alex
either use os.path.join to concat paths, or pathlib for slash syntax.
Anonymous
But now I'm getting this one
Anonymous
either use os.path.join to concat paths, or pathlib for slash syntax.
if settings.STATIC_ROOT and os.path.abspath(settings.STATIC_ROOT) == os.path.abspath(root): File "/app/.heroku/python/lib/python3.7/posixpath.py", line 378, in abspath path = os.fspath(path) TypeError: expected str, bytes or os.PathLike object, not tuple
Anonymous
post the full traceback on pastebin
https://pastebin.com/2jUVzhSg
Alex
https://pastebin.com/2jUVzhSg
Have you set STATIC_ROOT in your settings?
Anonymous
Have you set STATIC_ROOT in your settings?
Yes with this one os.path.join(BASE_DIR, 'staticfiles')
Alex
Yes with this one os.path.join(BASE_DIR, 'staticfiles')
If you get your BASE_DIR via pathlib, then you use / (forward slash) syntax to cancat paths.
Anonymous
Okay
Anonymous
But now this one comes FileNotFoundError: [Errno 2] No such file or directory: '/tmp/build_1a26db13_/static'
Anonymous
full traceback again please
https://pastebin.com/QqRsGhWQ
Alex
https://pastebin.com/QqRsGhWQ
do you have STATICFILES_DIRS? How is it defined?
Anonymous
do you have STATICFILES_DIRS? How is it defined?
Yes os.path.join(BASE_DIR, "static"),
Anonymous
Why ?
Jack👨🏻‍💻
STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static') ]
Jack👨🏻‍💻
this is what alex is talking about
Jack👨🏻‍💻
i think
Alex
Why ?
Slash. Syntax
Anonymous
I didn't use that
Anonymous
Because concat was working fine
Jack👨🏻‍💻
Slash. Syntax
STATIC_URL = '/static/' you mean this one?
Jack👨🏻‍💻
ok
Anonymous
🙄🙄
Anonymous
Fav
SMTPAuthenticationError at / (535, b'Incorrect authentication data') i have email sending project . work well in localhost , when i host in live server (hosted in c panal) i got this error
enansi
SMTPAuthenticationError at / (535, b'Incorrect authentication data') i have email sending project . work well in localhost , when i host in live server (hosted in c panal) i got this error
Are you setting some environment variables in localhost that you forget to set on the server? i.e. these variables, EMAIL_HOST_USER, EMAIL_HOST_USER, EMAIL_USE_TLS, EMAIL_USE_SSL
Ali
Hello friends I had a question, I use my django ORM, a simple query that when I execute it by django orm it run in 4000 milisecond , then when i execute my direct sql of django or execute by query it run in 30 milisecond
Ali
i user mysql db and config it by defult options
Sai
Hi everyone Django is not identifying the testcases I written. Need help
cj
Hi everyone Django is not identifying the testcases I written. Need help
read this: https://docs.djangoproject.com/en/3.1/topics/testing/
Sai
Hi everyone Django is not identifying the testcases I written. Need help
One more point to be added. I want to test my APIs
enansi
Hello friends I had a question, I use my django ORM, a simple query that when I execute it by django orm it run in 4000 milisecond , then when i execute my direct sql of django or execute by query it run in 30 milisecond
Do Queryset.explain() and you will probably find that the queryset you are writing for Django ORM is generating very different SQL from your raw SQL query. Then you could either optimize the queryset, or execute raw sql from Django
__init__
Who to do netsed serializer in DRF
Arezoo
Hi .i used generic.RetrieveAPIVIEW class in drf django
Arezoo
and i in this class i used get_object method ..in this method return output=get_objects_or_404(mymodel,id=2) ..how can i add new field in this query? When i used output.newfield=4 ..it can not add this field to output
inchidi
and i in this class i used get_object method ..in this method return output=get_objects_or_404(mymodel,id=2) ..how can i add new field in this query? When i used output.newfield=4 ..it can not add this field to output
put the new field inside your serializer, for example: class YourSerializer(ModelSerializer): new_field = serializers.SerializerMethodField() class Meta: model=YourModel fields="__all__" def get_new_field(self, obj): return 4
Arezoo
I can not ..becuase this field is new query from other model that not related to this serializer ..and this query get input
Arezoo
This query need input ..for example id ...i can not access in serializer ..i access this field in self.kwargs that there is in views.py
Arezoo
In serializer?
inchidi
yup
Arezoo
Thanks alot .now i test🙏
inchidi
Who to do netsed serializer in DRF
here's an example class YourSerializer(Serializer): first_child = YourAnotherSerializer()
Arezoo
It works..thanks alot..🌹🙏
M❄️hdi
Hello Can everyone explain writing asynchronous in django ? The say NodeJS is very good at this and so much faster!
Anonymous
https://stackoverflow.com/questions/65015442/recieving-plain-js-code-file-in-the-axios-get-response-in-react-while-trying-tp Hi guys i have a problem with getting response data from drf backend while trying to make axios request from react frontend . IT should actually respond wth user details but it respond with a html code file more specifically the same build file that is in build folder for react code in drf project
Anonymous
And one thing. More i am only getting this error when i am using reacts build file and loading the whole code on localhost:8000. Whne i run backend and frontend individually and make requests it runs well
Peak
hello How can I improve the response time to a query in my django project. i am using MYSQL database. As i used foreign keys, it is not possible to use partitioning. any other ideas? thanks.