Posts by Victor Fernandes • 443 points
28 posts
-
0
votes1
answer41
viewsA: Show internet image in my Django app
You do not need to use {%Static '' %} in this case, just pass the url normally, this way: <img src='http://s3.amazonaws.com/caymandemo/wp-content/uploads/sites/10/2015/09/30162427/sep2.jpg'>…
-
1
votes2
answers564
viewsA: Show login error messages in Python with Django
Use Django’s own messaging system, you can see all the options by clicking here. To send a login failure message, for example, you can try the following: from django.contrib import messages def…
-
1
votes1
answer110
viewsA: Form label is not shown on the #Django page
Try the following: n_cpf = BRCPFField(label='CNPJ') <form action="{% url 'app_web:novo_cliente' %}" method="POST"> {% csrf_token %} {% for field in form %} <p> {{ field.label_tag }} {{…
-
1
votes2
answers437
viewsQ: Regex to find text between square brackets
I’m trying to create a regex to identify the following occurrence: [Ticket: 20021501280806] I need an expression that identifies the ticket number, but only within the string [Ticket: ]. Actually I…
-
2
votes1
answer737
viewsA: Django: How to set MEDIA_URL, MEDIA_ROOT and upload_to correctly?
Do the following on your urls.py: urlpatterns = [ path('admin/', admin.site.urls), path('', HomePageView.as_view(), name='home'), path('list/', ListaOrdemServico.as_view(),…
-
7
votes1
answer364
viewsQ: Problems with CORS in Django using AWS S3
My application uses a Bucket on AWS to host the static and MEDIA files, here’s the link: http://memoriasclubeturismoenv.us-east-2.elasticbeanstalk.com/gilson-rolim-02-12-2019 or…
-
1
votes1
answer83
viewsA: How can I run a function when user registers Django
Add this into the "create_user function": import os BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) os.mkdir(os.path.join(BASE_DIR, 'Collections/{}'.format(self.username)))…
-
4
votes1
answer2061
viewsA: Django: Modulenotfounderror: No module named
Try the following: from app1.models import ObjetoX objeto_x = ObjetoX(parm=1)
-
0
votes1
answer127
viewsA: Django Application Deploy with Apache
In your Settings.py, in the "TEMPLATES" variable, do the following: TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'templates')],…
-
0
votes1
answer486
viewsA: Problems with Urls in Django
Try the following: from django.contrib import admin from django.urls import include, path from rest_framework import routers from ChatBot.views import UserViewSet from ChatBot.views import…
-
0
votes1
answer84
viewsA: Formulário Django
To use this form, you will have to use the same Names and id’s, for this, you will have to set the id’s and Names of the Forms, you can do so: <div class="row"> <label for="cidade-cad"…
djangoanswered Victor Fernandes 443 -
0
votes1
answer161
viewsA: Help with Django Template Directory
In its variable TEMPLATES add "template" in the 'DIRS': []. Django will automatically search for the template folder within the applications. Should stay like this: TEMPLATES = [ { 'BACKEND':…
-
0
votes1
answer229
viewsA: How to make a date filter in Django
Try the following: from datetime import datetime from datetime import timedelta from django.views import generic class SuaListView(generic.ListView): queryset =…
-
0
votes1
answer61
viewsA: Insert direct tuple with SQL in a Django view
I went through a similar situation which I solved using Django Rest Framework to perform the operations. Create the endpoints in project 2 and access through project 1, you can create views to…
-
1
votes1
answer361
viewsA: Error trying to initialize a cloned Django project from github (Modulenotfounderror: No module named 'django_filters')
Just install the project dependencies as shown errors. Check if there is a file in the project called Restore.txt, if not, install the dependencies as the errors shown in the console. To isntalar…
-
1
votes1
answer681
viewsA: How to save a <select> option in the database? DJANGO
Use a Createview to resolve this, try the following: from django.views import generic from django.contrib.messages.views import SuccessMessageMixin from django.urls import reverse_lazy class…
djangoanswered Victor Fernandes 443 -
0
votes1
answer79
viewsA: How can I get access to deleted objects in Django?
To query this data, you will need to log it somewhere. I suggest that instead of deleting the vehicle after exit, only the "deactivate", you can add an "active" Boolean attribute to your model, this…
-
1
votes1
answer122
viewsA: Slow loading of files into Static folder in Django
Eudson, when accessing and viewing the 304 code, means that the file has not been modified, for this reason, is loaded what is cached, when this occurs, just press Control + F5, this will load all…
-
0
votes1
answer32
viewsA: Select random mysql with Django
If I understand correctly, you want to return a random user, then follows: User.objects.all().order_by('?').first() The . first() is equivalent to [0]. You can read more about ordering here.…
-
1
votes1
answer705
viewsA: Import: cannot import name 'Usuario' from 'usuarios.models
Delete the section from usuarios.models import Usuario and do the following: usuario = models.ForeignKey('usuarios.Usuario', on_delete=models.CASCADE) The same is valid for all snippets where you…
djangoanswered Victor Fernandes 443 -
0
votes1
answer101
viewsA: Correctly set URLS in Django
As you used a include in the project’s main urls.py, you will need to access the Domain/login/login or Domain/login/Challenge address, if you want to change this, you can access the main urls.py…
-
0
votes1
answer123
viewsA: Python Text Message Validation
You can do the following to render your form in the template: {% for field in form %} {{ field.errors }} {{ field.label_tag }} {{ field }} {% endfor %} With this, the type of error above each field…
-
0
votes3
answers805
viewsA: I’m having a problem with Django-views, he’s not saving my form
Good morning Amanda, All right? Amanda, I rewrote the code a little bit, I hope it helps: #forms.py from .models import Candidato from django import forms class CandidatoForm(forms.ModelForm): class…
djangoanswered Victor Fernandes 443 -
0
votes1
answer57
viewsA: Syntaxerror: Invalid Syntax
Missing close a parenthesis, see: while True: opcao = int(input("Digite a opcao desejada: ")) if opcao == 1: arquivo = open("textos.txt", 'w')
pythonanswered Victor Fernandes 443 -
1
votes1
answer183
viewsA: How to create a view with more than one form in Django
Good morning the/, You can render multiple Forms used the context_data method, thus: def get_context_data(self, **kwargs): kwargs['form1'] = MeuForm1() kwargs['form2'] = MeuForm2() kwargs['form3'] =…
-
1
votes1
answer524
viewsA: Catch id and name via form, both forenig key
Brother, I’ve given the code refactored using CBV, try ai: #models.py class Negocio(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) empresa =…
-
0
votes1
answer61
viewsA: Is it necessary to create an app for each entity in a Django project?
Dude, it depends a lot, but in general, I like to divide my application into modules, for example, in the case of an e-commerce, I would create an app called "categories", another one called…
-
0
votes1
answer415
viewsA: Loading 2 form on the same page and saving them
Good morning, Dude, I needed to do something similar on my system, I have several different tables in the database, so several different formats rendered on the same page. I don’t know if the shape…