django-templates

Django – after sign-in template don't know that user is authenticated

Django – after sign-in template don't know that user is authenticated Question: Below code probably works (no errors present): views.pl class SignInView(View): def get(self, request): return render(request, "signin.html") def post(self, request): user = request.POST.get(‘username’, ”) pass = request.POST.get(‘password’, ”) user = authenticate(username=user, password=pass) if user is not None: if user.is_active: login(request, user) return HttpResponseRedirect(‘/’) else: …

Total answers: 2

Django: TemplateSyntaxError – Could not parse the remainder

Django: TemplateSyntaxError – Could not parse the remainder Question: Exception Value: Could not parse the remainder: ‘[‘image/jpeg’,’ from ‘[‘image/jpeg’,’ Why am I getting this TemplateSyntaxError for the code below? {% for file in resource.files.all %} {% if file.file.content_type|lower in [‘image/jpeg’, ‘image/png’, ‘image/gif’] %} <a class="resource-image" title="{{ file.id }}" href="{{ file.file.url }}"> <img width="100%" src="{{ file.file.url …

Total answers: 1

Having trouble with notifications feature in Django

Having trouble with notifications feature in Django Question: Created a notification feature in my django project. I’ve got all the functionality down and it works except for one thing. I want the template to display a different message depending on what action is committed. All it currently displays is ‘The ticket has been updated’ instead …

Total answers: 1

TemplateDoesNotExist at /accounts/login/

TemplateDoesNotExist at /accounts/login/ Question: I have checked the answers here, here, here, and here, and though I am getting the same error apparently I have a different root cause since those answers do not work for me. Here’s the problem: I am using Django’s LoginView, overriding the template name, but it only sometimes works. If …

Total answers: 1

Django execute previous action on refresh

Django execute previous action on refresh Question: I have tried to add a book in to the database using an HTML form. After the submission, the page redirect to a page where all the books are listed .Then whenever I refresh the page , the data is became duplicated. How do I resolve this problem? …

Total answers: 1

Django – Problem with Model Manager – Query

Django – Problem with Model Manager – Query Question: I’m still a beginner and I’m stuck in a challenging spot for me. I can’t get data from a foreign key table to be inserted "correctly" into a column of a ListView. I basically want to create a list view of a table (FeatureFilm). This also …

Total answers: 1

Django media image not showing up in template but can acces it via …/media/thumbnail/image.png

Django media image not showing up in template but can acces it via …/media/thumbnail/image.png Question: Altough context does render in html, i can use other variables but cant accsess the image. My code is: html: {% for a in Manga %} <div class="manga_container"> <div class="manga_image"> <p>{{a.manga_image}}</p> <img src="{{ x.manga_image.url }}" alt=""> </div> </div> {%endfor%} model: …

Total answers: 1

how to call a function as a context in django

how to call a function as a context in django Question: class User(AbstractUser): GENDER_STATUS = ( (‘M’, ‘Male’), (‘F’, ‘Female’) ) address = models.TextField(null=True, blank=True) age = models.PositiveIntegerField(null=True, blank=True) description = models.TextField(null=True, blank=True) gender = models.CharField(max_length=1, choices=GENDER_STATUS, null=True, blank=True) phone = models.CharField(max_length=15, null=True, blank=True) def get_full_name(self): return f'{self.first_name} {self.last_name}’ I declare a function get_full_name and …

Total answers: 2

How Can I Display Multiple Models In a Django ListView?

How Can I Display Multiple Models In a Django ListView? Question: I am trying to display several models via a ListView. After some research…I have determined that I can do something like… class MultiModelListView(LoginRequiredMixin,ListView): model = MultiModel context_object_name = ‘thing_list’ template_name = ‘view_my_list.html’ paginate_by = 15 def get_context_data(self, **kwargs): context = super(MultiModelListView, self).get_context_data(**kwargs) list1 = …

Total answers: 1