I am reading the book ‘Django for APIs’ from ‘William S. Vincent’ (current edition for Django 4.0) In chapter 4, I cannot run successfully the command python manage.py collectstatic. I get the following error: I have the exact same settings like in the book in settings.py: I couldn’t find any explanation for it. maybe someone can point me in the
Tag: django
How do I solve django.db.utils.IntegrityError: UNIQUE constraint failed?
How do I solve django.db.utils.IntegrityError: UNIQUE constraint failed? error code is django.db.utils.IntegrityError: UNIQUE constraint failed: Movies_comment.user_id, Movies_comment.tv_or_movie_id. This error occurs Comment(comment=form.cleaned_data[“comment”],user=request.user,stars=form.cleaned_data[“stars”],tv_or_movie=tv_or_movie_object).save() views.py models.py helper_views.py Answer tv_or_movie before saving i.e.
python manage.py collectstatic not working: TypeError: sequence item 0: expected str instance, NoneType found
I have been following this video on Youtube: https://www.youtube.com/watch?v=inQyZ7zFMHM1 My project so far is working fine with static files and all the files load and work properly. So, now I have to deploy the website on Heroku and for that, I uploaded the database on Amazon AWS using this video. After bucket creation, I did the configurations as mentioned in
How to Join Subqueries in Django ORM
I’m a beginner Django and I have been stuck on the following problem for a while. The basic thing I would like to achieve is that when client makes a GET list api request with a time period parameter (say 3 months) then the server would return an aggregation of the current 3 months data and also show an extra
Django – fresh database and no such table
I’m using my complex jobs app in production and it works fine, with sqlite database. I’m trying to create new database from scratch and I cannot do that nor using migrations nor trying to make them once again: When I’m trying to reuse my migrations: When I’ve tried to remove all migration files: How can I investigate what is going
Django test uses wrong database in some cases
I try to setup my Django tests, and I noticed that when I run all tests TestRunner uses correct test database (for all aliases): docker-compose exec my_project python manage.py test –keepdb But when I run tests for specific module, it uses the original database: docker-compose exec my_project python manage.py test –keepdb apps.my_module What is the reason of such behavior? Using
Django multiple params link
I have this urls.py first path with one args works good with reverse func in some file how i can do this -> from …/calendar/2020-01-01 to …/calendar/2020-01-01/100 in template without using context and 2 args like url ” ” date arg2 something like <a href = “{% url ‘schedule’ *** %}> tries reverse full path with two args Answer If
Querying One model item from another model
I have a list of Artist (Musicians) and their Albums they created. T My models looks like the following: My Views My HTML is the following: My shell looks like the following: I would like to learn how to select One artist “Eminem” and have all albums associated with his model listed on the next page. So i would select
Unable to use ManyToMany Field with Django and Postgres
I am working on a project with Django, Postgres. I typed that: When I type that: I got that: Then if I type that: I got that: Whereas the field name exists. Models.py: Answer M2M relationship means – you have many objects. user.food.name get attrbute name from M2M manager. Probably you mean user.food.all().name – this code get attrbute name of
Django forms: not adding attributes
I’m aware that there is many post like this, but can you spot the typo or error in my code? I’m adding custom classes to my forms but when I inspect the element on the web page there are none. The same goes for placeholder. Code: Views.py: Template file: Forms.py: Answer I think, you already specified the fields name and