Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Django tests pass locally but not on Github Actions push
My tests pass locally and in fact on Github Actions it also says "ran 8 tests" and then "OK" (and I have 8). However, the test stage fails due to a strange error in the traceback. Traceback (most recent call last): File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/db/backends/utils.py", line 82, in _execute return self.cursor.execute(sql) File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 421, in execute return Database.Cursor.execute(self, query) sqlite3.OperationalError: near "SCHEMA": syntax error The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/runner/work/store/store/manage.py", line 22, in <module> main() File "/home/runner/work/store/store/manage.py", line 18, in main execute_from_command_line(sys.argv) File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line utility.execute() File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/core/management/commands/test.py", line 23, in run_from_argv super().run_from_argv(argv) File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv self.execute(*args, **cmd_options) File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute output = self.handle(*args, **options) File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/core/management/commands/test.py", line 55, in handle failures = test_runner.run_tests(test_labels) File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/test/runner.py", line 736, in run_tests self.teardown_databases(old_config) File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django_heroku/core.py", line 41, in teardown_databases self._wipe_tables(connection) File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django_heroku/core.py", line 26, in _wipe_tables cursor.execute( File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute return self._execute_with_wrappers(sql, params, many=False, executor=self._execute) File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers return executor(sql, params, many, context) File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute return self.cursor.execute(sql, params) File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__ raise … -
Django "__str__ returned non-string (type tuple)"
I've seen similar problems but still cannot solve mine. I'm making e-commerce ticket system. Here's the code. class Event(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=255, db_index=True) banner = models.ImageField(upload_to='banners/' ,null=True, blank=True) description = models.TextField(blank=True) address = models.CharField(max_length=255) slug = SlugField(max_length=255, blank=True) event_date_time = models.DateTimeField() price_1 = models.DecimalField(max_digits=5, decimal_places=2) pool_1 = models.IntegerField() pool_date_1 = models.DateTimeField() price_2 = models.DecimalField(max_digits=5, decimal_places=2) pool_2 = models.IntegerField() pool_date_2 = models.DateTimeField() price_3 = models.DecimalField(max_digits=5, decimal_places=2) pool_3 = models.IntegerField() def __str__(self): return ( self.id, self.name, self.banner, self.description, self.address, self.slug, self.event_date_time, self.price_1, self.pool_1, self.pool_date_1, self.price_2, self.pool_2, self.pool_date_2, self.price_3, self.pool_3 ) class Ticket(models.Model): id = models.AutoField(primary_key=True) event = models.ForeignKey(Event, related_name='ticket', on_delete=models.CASCADE) slug = SlugField(max_length=255, blank=True) date_sold = models.DateTimeField() price = models.DecimalField(max_digits=5, decimal_places=2) bought_by = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, related_name='buyer') promotor = models.CharField(max_length=4, blank=True) def __str__(self): return ( self.id, self.slug, self.date_sold, self.price ) I'm not sure which one of those values returns error, could someone please explain to me which value and why returns tuple? I've tried many combinations and was still not able to solve it. -
Django aggregate combine two expressions in one dict as output field
I have this code, which aggregates queryset and count amount of objects with condition: queryset = queryset.aggregate( first_win=Count( "score", filter=Q(score__first_score=5), output_field=FloatField(), ), second_win=Count( "score", filter=Q(score__second_score=5), output_field=FloatField(), ), ) And this is response format: { "first_win": 78.26086956521739, "second_win": 17.391304347826086 } I want to change it and combine two or more values in one. Can I somehow make it look like this? { "win_info": { "first_win": ... "second_win": ... } } -
Authentication failed django
I get an error password authentication failed for user "usertodoproject". Really losing my patience, so far I have done couple of new databases and used fpr example this ALTER USER todouser WITH PASSWORD 'todo'; it did not help either. Any ideas? settings.py DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'todoproject', 'USER': 'usertodoproject', 'PASSWORD': 'todoprojectpass', 'HOST': 'db', 'PORT': '5432', } } db: image: postgres environment: - POSTGRES_DB=todoproject - POSTGRES_USER=usertodoproject - POSTGRES_PASSWORD=todoprojectpass ports: - 5432:5432 -
Django Rest Framework Send Image in Email
Hello I have faced an Issue regarding sending email In django rest API. The Idea is user sends email and Uploads image from serializer part and I want to send same image to users Email. But I am not getting image in email. here is the code I have been working. models.py class Mail(BaseModel): full_name = models.CharField(max_length=100) image = models.ImageField(upload_to=mail_image_to) email = models.EmailField() below is my serializer class MailSerializer(serializers.ModelSerializer): class Meta: model = Mail fields = '__all__' class AddMailSerializer(MailSerializer): class Meta(MailSerializer.Meta): fields = ( 'full_name', 'image', 'email', ) views.py class AddMailView(generics.CreateAPIView): """ Use this endpoint to add mail """ serializer_class = serializers.AddMailSerializer def perform_create(self, serializer): return AddMailUseCase(serializer=serializer).execute() I usually write my rest of code in usecase.py class AddMailUseCase: def __init__(self, serializer): self.serializer = serializer self.data = serializer.validated_data def execute(self): self._factory() def _factory(self): self._mail = Mail(**self.data) self._mail.save() SendEmail( context={ "fullname": self.data['full_name'], 'image': self.data['image'] } ).send(to=[self.data['email']]) I am using django-templated-mail 1.1.1 to send email here is my rest of code. from templated_mail.mail import BaseEmailMessage class SendEmail(BaseEmailMessage): template_name = 'email.html' and finally my email.html {% load i18n %} {% block subject %} {% blocktrans %}Email Successfully Sent {% endblocktrans %} {% endblock subject %} {% block text_body %} {% blocktrans %}You're receiving this … -
SimpleJWT TokenObtainPairView API Precondition required
I am implementing authentication system in Django using SimpleJWT. I have done the installations, and added the urls, similar to the tutorial. But when I'm running the curl request to verify. I'm getting the 428 "Precondition required" status along with empty response. Its working when I'm testing on my local though. settings.py SIMPLE_JWT = { 'ACCESS_TOKEN_LIFETIME': timedelta(minutes=5), 'REFRESH_TOKEN_LIFETIME': timedelta(days=30), 'ROTATE_REFRESH_TOKENS': False, 'BLACKLIST_AFTER_ROTATION': False, 'UPDATE_LAST_LOGIN': False, 'ALGORITHM': 'HS256', 'VERIFYING_KEY': None, 'AUDIENCE': None, 'ISSUER': None, 'JWK_URL': None, 'LEEWAY': 0, 'AUTH_HEADER_TYPES': ('Bearer',), 'AUTH_HEADER_NAME': 'HTTP_AUTHORIZATION', 'USER_ID_FIELD': 'id', 'USER_ID_CLAIM': 'user_id', 'USER_AUTHENTICATION_RULE': 'rest_framework_simplejwt.authentication.default_user_authentication_rule', 'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',), 'TOKEN_TYPE_CLAIM': 'token_type', 'JTI_CLAIM': 'jti', 'SLIDING_TOKEN_REFRESH_EXP_CLAIM': 'refresh_exp', 'SLIDING_TOKEN_LIFETIME': timedelta(minutes=5), 'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=1), } Also appended 'rest_framework_simplejwt', in the INSTALLED_APPS. Can anyone help me with this? -
Django Debug Toolbar
I'm using Django But Django Debug Toolbar doesn't show on Chrome & Firefox. I have done all steps for config, that said on the official site of Django-debug-toolbar. Django Version: 3.1.4 Python Version: 3.9.0 -
Django: Registration form on modals available on multiple pages
I have the following scenario: I have a navbar available on all the pages of my website. The navbar has a button that opens a modal for registering. The modal has a form. The corresponding Django form is injected via a Context Processors (as recommended here). My problem, however, is that I don't know how to process the request (registration or login) in such a way that I don't need to have this logic repeated on every view. -
why pip freeze > requirements.txt giving error?
pip freeze > requirements.txt giving an error WARNING: Could not generate requirement for distribution -ip 21.0 (c:\python39\lib\site-packages): Parse error at "'-ip==21.'": Expected W:(abcd...) How to remove this error and what the error exactly it is? -
how to find mutual objects in 2 queries in Django
I'm doing 2 queries in Django and I need to find the objects that exist in both quires, is there a fast ORM or function for this? Here is my code : from_lines_objects = Line.objects.filter( Q(starting_station=from_station_object) | Q(end_station=from_station_object) | Q( inlinestation__in_line_station=from_station_object)).distinct() to_lines_objects = Line.objects.filter( Q(starting_station=to_station_object) | Q(end_station=to_station_object) | Q( inlinestation__in_line_station=to_station_object)).distinct() what I need to do is to create a third variable that contains only the objects that existed in both queries .. any help? -
which I should prefer user.address.id or user.address_id in django?
I have two models User and Address, User has a foreign key relationship with Address model, I want to get the Address id from the user object, which query I should prefer, or is there any other efficient way? user = User.objects.last() we have two queries which one is efficient: user.address.id or user.address_id Thanks -
Some objects of django forms are not saved in database?
I created a custom register form and previously it only asked for username and password.Then I added some sections such as name , lastname and email to the user registration section. After adding these, it now doesn't happen when registering the username in the database during user registration. And also name and email information is not registered. models.py from django.db import models class Register(models.Model): first_name = models.CharField(max_length=50,verbose_name="First Name") last_name = models.CharField(max_length=50,verbose_name="Last Name") username = models.CharField(max_length=50,verbose_name="Username") email = models.EmailField(verbose_name="Email") password = models.CharField(max_length=50,verbose_name="Password") confirm = models.CharField(max_length=50,verbose_name="Confirm Password") def __str__(self): return self.title forms.py from django import forms from.models import Register class LoginForm(forms.Form): username = forms.CharField(label="Username") password = forms.CharField(label="Password",widget=forms.PasswordInput) class RegisterForm(forms.ModelForm): class Meta: model = Register widgets = { 'password': forms.PasswordInput(), 'confirm': forms.PasswordInput(), } fields = ["first_name","last_name","username","email","password","confirm"] views.py from django.contrib.auth.backends import UserModel from django.shortcuts import render,redirect from .forms import LoginForm, RegisterForm from django.contrib.auth.models import User from django.contrib.auth import login,authenticate,logout from django.contrib import messages from django.contrib.auth.decorators import login_required # Create your views here. def register(request): form = RegisterForm(request.POST or None) if form.is_valid(): password = form.cleaned_data.get('password') username = form.cleaned_data.get('username') last_name = form.cleaned_data.get('last_name') email = form.cleaned_data.get('email') first_name = form.cleaned_data.get('first_name') newUser = User(username = username) newUser = User(first_name = first_name) newUser = User(email = email) newUser = User(last_name … -
Change django language code from URL pattern
I have this languages code setup on my Django application. LANGUAGES = [ ('en', _('English (US)')), ('de', _('Deutsch')), ('fr',_('Français')), ('ja',_('日本語')),# -> JP ('ko',_('한국어')),# -> KR ] And on the url patterns i have the following setup: urlpatterns = i18n_patterns( path('', include('main.urls')), prefix_default_language=False ) So my application has the languages folder prefixed on the URLs. But i need the languages ja and ko to work from other prefixes, jp and kr, respectively. I tried using a middleware to override the request.path_info and the site responds on the required urls but it builds the internal links on the bad urls. -
Django using MySQL deployment - Window server apache mod_wsgi
I don't know how to deploy Django web application using MySQL on Window Server. I did some searches on google but i can't find anything relating to the topic. There are some videos on google about deploying Django on Window Server, but most of them use SQLite. I need some guidance for this setup or any good articles would be appreciated. Thanks in advance. -
Adding an Array to an a href link using Javascript/Jquery
I'm currently writing a functionality, whereby the users will click on a particular email and this will be added to a list in the local storage, thereafter, the user will click a button, essentially that button should popular a href tag, so that all the mail addresses are copied to user's default email settings (in my case outlook). My question is how do you convert this into an email format?, I have tried loading it into the tag and it works, but then Django interprets this as a URL, not a mailing list? So far I have the following: <td class="virtualTd" onclick="putThis(this)">{{ client.email }}</td> <script> const emails_list = [] function putThis(control) { var email = control.innerText; emails_list.push(email); } </script> This populates an array with all the addresses, Thereafter, the user can click this button to load the data in to local storage, with the ultimate intention to load the outlook email <a href="#" id="sendEmail" class="btn btn-primary" onclick="popEmail()"> Email Client </a> <script> function popEmail() { const jsonArr = JSON.stringify(emails_list); localStorage.setItem("array", jsonArr); const str = localStorage.getItem("array"); const parsedArr = JSON.parse(str); console.log(parsedArr); var a = document.getElementById('sendEmail'); a.href = parsedArr; } </script> -
Django uploading images via admin panel error
Hello when I want to test uploading images via admin panel I keep getting an error. No such file or directory: '/todoapp/media/cola.png'. I have no idea what did I wrong and unluckily I have to paste ton of code. model: class Profile(models.Model): user = models.OneToOneField(User, on_delete=CASCADE) image = models.ImageField(upload_to='media/', default='ww1.jpg') urls.py urlpatterns =+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) tree: ├── docker-compose.yml ├── Dockerfile ├── home │ ├── admin.py │ ├── apps.py │ ├── forms.py │ ├── models.py │ ├── signals.py │ ├── static │ │ └── home │ │ ├── etc. etc. │ ├── templates │ │ └── home │ │ ├── etc. etc. │ ├── tests.py │ ├── urls.py │ └── views.py ├── manage.py ├── media │ ├── dress.png │ └── pictures │ └── ww1.jpg ├── requirements.txt ├── todoapp │ ├── asgi.py │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-39.pyc │ │ ├── settings.cpython-39.pyc │ │ ├── urls.cpython-39.pyc │ │ └── wsgi.cpython-39.pyc │ ├── settings.py │ ├── urls.py │ └── wsgi.py └── travis_script.sh -
HTML form not passing data in Django views.py, passing null string
I have been trying to build a multi step form and when submitted the form, the default from select tag and empty string from input tag is passed. And thus the conversion to integer in views.py is showing a value error. I have added name attribute in the html forms yet the values aren't being passed. Could anyone help me what I am missing? HTML <section> <div class="container"> <form method="POST" action="{% url 'cost' %}"> {% csrf_token %} {{form}} <div class="step step-1 active"> <div class="form-group"> <div class="custom-select type" style="width:200px;"> <p class="details">Product Type</p> <div class="buff"></div> <select id="type" name="type"> <option value="0">Select type:</option> <option value="1">Shopping Bag</option> <option value="2">Card</option> <option value="3">Box</option> </select> </div> </div> <div class="buff"></div> <div class="buff"></div> <div class="buff"></div> <div class="buff"></div> <div class="buff"></div> <div class="form-group"> <div class="custom-select purpose" style="width:200px;"> <p class="details">Product Purpose</p> <div class="buff"></div> <select id="purpose" name="purpose"> <option value="0">Select Purpose:</option> <option value="1">Corporate Gifts</option> <option value="2">HR</option> <option value="3">Packaging</option> </select> </div> </div> <button type="button" class="next-btn position">Next</button> </div> <div class="step step-2"> <div class="form-group"> <div class="buff"></div> <div class="buff"></div> <div class="buff"></div> <div class="buff"></div> <p class="details">Quantity of Product:</p> <div class="buff"></div> <input type="text" placeholder="How many pieces..." name="quantity"> <div class="buffer"></div> </div> <button type="button" class="previous-btn position">Prev</button> <button type="button" class="next-btn position">Next</button> </div> <div class="step step-3"> <div class="form-group"> <div class="buff"></div> <div class="buff"></div> <div class="buff"></div> <p … -
Fetched objects from django are displayed as numbers/ids
I'm using React frontend and Django backend. I've managed to make it so users can add rats to their account, however when I wanna fetch details about the rats the details are displayed as numbers, I'm assuming the id of the detail? Here's an example. This is what you get if you view one of the rats, frontend-wise: User: 12, Rat Name: newrat Rat Body colour: 3, Eye colour: 3 So as you can see, you get the id (?) of each detail except the rat name. It belongs to the user with the id of 12, and the 3rd body colour created, etc. Here's my models: class EyeColour(models.Model): name = models.CharField(max_length=255) def __str__(self): return self.name class BodyColour(models.Model): name = models.CharField(max_length=255) def __str__(self): return self.name class rat(models.Model): name = models.CharField(max_length=132, null =True) body_colour = models.ManyToManyField(BodyColour, related_name='bodycolour') eye_colour = models.ManyToManyField(EyeColour, related_name='eyecolour') user = models.ForeignKey(User, on_delete=models.CASCADE, null = True) def __str__(self): return self.name Serializers: class EyeColourSerializer(FlexFieldsModelSerializer): class Meta: model = EyeColour fields = '__all__' class BodyColourSerializer(FlexFieldsModelSerializer): class Meta: model = BodyColour fields = '__all__' class RatSerializer(FlexFieldsModelSerializer): class Meta: model = rat # fields = '__all__' exclude = ['bio'] # read_only_fields = ['eye_colour', 'body_cdolour'] expandable_fields = { 'EyeColour': ('accounts.EyeColourSerializer', {'many': False}), 'Image': ('accounts.ImageSerializer', … -
how can i get mail from from_mail in django?
I am sending mail from my django site. Everything is fine and mail is also sent and received successfully, but not from_email(that put on email field in contact form). Email sent from EMAIL_HOST_USER = 'example@gmail.com' that I put on setting.py. def contact(request): if request.method == 'POST': name = request.POST['name'] email = request.POST['email'] subject = request.POST['subject'] phone = request.POST['phone'] message = request.POST['message'] try: send_mail(subject,message,email,['to@gmail.com',],fail_silently=False) messages.success(request, 'We get your message and reply shortly...') except: messages.error(request, "failed") return render(request, 'pages/contact.html') I want mail will be sent from email(that user put on the email field) -
XMLParser and Json parser
i wrote an xml parser request and i need this : if the request was sent xml return the response in xml, without enforcing to send Accept header return Response(data, status=status.HTTP_200_OK, headers=headers,content_type= request.content_type) the content type t+is not working what can i do? -
Connect admins name and email to a group in Django settings.py
I added ADMINS in my settings.py and I put my name and email there. Is there any way to put a group name that I created in my Django admin page instead of using hardcoded names and emails? Let's say that I have created group named moderators and I want to assign this group to ADMINS in my settings.py -
Whenever I click a link, It downloads an empty html file instead of opening another page
I am developing a Todo app with Django. I am trying to have some links in every task container to forward it into a detailed page of the task. So whenever I run the server in localhost and try to click on those links. it downloads empty Html files (with the name 'download.html'). I trided to figure if the problem is in the path of the URL but It turns out to be fine. <div class="col-md-4"> <a class="btn btn-info btn-sm" href="edit-task/">Edit</a> <a href="" class="btn btn-danger btn-sm">Delete</a> </div> I cleared the browser data like google chrome community suggestion, but nothing changed, Please Help me. Do not worry! everything in urls.py and views.py is set correctly -
Merge two records to one record based on an item in bootstrap table
I have a Django web app for managing books, using Django rest framework and bootstrap table. In the frontend, the user want to merge two records (part time and full time) to one record (ALL) in frontend. That is, merging the below two records to one one row with course type "ALL" in the frontend. enter image description here enter image description here HTML: <table contenteditable='true' class="table table-bordered table-xl" width="100%" cellspacing="0" style="font-size: 1.0rem;" id="bk-table" data-toggle="table" data-toolbar="#toolbar" data-cookie="true" data-cookie-id-table="materialId" data-show-columns="true" data-show-export="true" data-export-types="['excel','pdf']" data-height="1650" data-click-to-select="true" data-id-field="id" data-show-footer="true" data-url="/api/materials/" data-query-params="queryParams" data-remember-order="true" data-pagination="true" data-side-pagination="client" data-total-field="count" data-data-field="results"> <thead class="thead-dark" > <tr contenteditable='true'> <th class ='courseCode' data-field="courseCode" data-formatter="renderCourse">Course Code</th> <th data-field="type" data-formatter="renderCourse">Course Type</th> <th class ='title' data-field="book.title" data-formatter="renderCourse">Course Material Title </th> </thead> </table> RESTful API(using DRF): class BookSerializer(serializers.HyperlinkedModelSerializer): publisher = serializers.ReadOnlyField(source='publisher.name') class Meta: model = Title fields = ['id', 'url', 'title'] class CourseSerializer(serializers.ModelSerializer): # semester = SemesterSerializer(many=False) courseCode = serializers.ReadOnlyField(source='courseInfo.code') courseTitle = serializers.ReadOnlyField(source='courseInfo.title') courseType = serializers.ReadOnlyField(source='courseInfo.type') year = serializers.ReadOnlyField(source='semester.year') month = serializers.ReadOnlyField(source='semester.month') term = serializers.ReadOnlyField(source='semester.term') school = serializers.ReadOnlyField(source='courseInfo.school.code') class Meta: model = Course fields = ['id', 'courseInfo', 'semester', 'courseCode', 'courseTitle', 'courseType'] class MaterialSerializer(serializers.ModelSerializer): book = BookSerializer(many=False) course = CourseSerializer(many=False) school = serializers.ReadOnlyField(source='course.courseInfo.school.name', allow_null=True) courseId = serializers.ReadOnlyField(source='course.courseInfo.id') year = serializers.ReadOnlyField(source='course.semester.year') month = serializers.ReadOnlyField(source='course.semester.month') term = serializers.ReadOnlyField(source='course.semester.term') quota … -
is there any other way i can use django @login_required parameter?
this little stuffs has been frustrating me since yesterday, i was trying to add @login_required parameter to my create function in django, the code works really well without adding the @login_required parameter, but bring page not found when i add @login_required. this is my code. urls.py app_name = 'accounts' urlpatterns = [ path('signup', views.signup_view, name='signupp') , path('login', views.login_view, name='loginn'), path('logout', views.logout_view, name='logoutt') ] views from django.contrib.auth.decorators import login_required @login_required(login_url='accounts/loginn/') def jayapp_create(request): return render(request, 'jayapp/jayapp_create.html' ) when i go to http://127.0.0.1:8000/jayapp/create/ it shows Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/jayapp/accounts/loginn/?next=/jayapp/create Using the URLconf defined in JayDjango.urls, Django tried these URL patterns, in this order: admin/ accounts/ jayapp/ [name='list-in'] jayapp/ log jayapp/ create [name='create'] jayapp/ / [name='detail'] backen/ ^media/(?P.*)$ The current path, jayapp/accounts/loginn/, didn’t match any of these. You’re seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page. -
DRF : Getting nestted serializer fields for custom checks
Here is my master and detail serializers. class MasterSerializer(serializers.ModelSerializer): class Meta: model = Master fields = ['id','date_signed','info1','info2'] class DetailSerializer(serializers.ModelSerializer): master = MasterSerializer(read_only=True) class Meta: model = Detail fields = ['id','master','date_start','date_end','info3','info4'...] def validate(self, attrs): # 1. check if date sign is always grater than date start # 2. check date start is greater than date end What i am trying to do is to check if the date_signed in master serializer is always a date before the date_start one. For that i need the date_signed in the detail serializer. So how can i get it. May be is a simpler question, but i am finding it difficult as i just started learning drf. I searched a lot, but couldnt get the solution i needed. Hope to get some help to point me in the right direction. Thanks in advance