Posts by Otávio Reis Perkles • 855 points
30 posts
-
2
votes1
answer1301
viewsA: 'Model' Object is not iterable
To popular the variable visitantes you’re using get_object_or_404() that behind the cloths will make a get() if you don’t find anything it will launch Http404 instead of Doesnotexist. The problem is…
-
0
votes3
answers119
viewsA: How do I reset the Flask server using if within the algorithm?
A game often relies on reading user input and reacts to it very quickly. Within game development there is a pattern that resolves this problem called game loop [²]. A game loop is literally a loop…
-
6
votes2
answers103
viewsA: Why is this loop infinite?
The variable t is not being used in the right way. From the moment you enter the second loop it will always scroll through the letters of text decreasing by 1 in t while t != 5: for i in text:…
-
0
votes1
answer66
viewsA: I cannot change the verbose_name of a field
Quoting the documentation in free translation: Each field, with the exception of Foreignkey, Manytomanyfield and Onetoonefield, receives an optional first argument - verbose name. If verbose name is…
-
0
votes2
answers56
viewsA: Category Names not shown. Object (1)
Fabio, you can choose the name that will appear for each Django template created by you. just implement the method: def __str__(self): return self.name In your case I’d be: from django.db import…
-
3
votes3
answers1463
viewsA: For with python time
I don’t think it’s possible to use a date for the purpose you want. calculations, operations and the like involving given are famous for obtaining a certain level of inherent 'complexity'. I think…
pythonanswered Otávio Reis Perkles 855 -
3
votes3
answers2829
viewsA: Accent error on Visual Studio output
You’re probably using the Character encoding wrong. Your question is likely to be duplicate But I will answer you as best I can. To understand well what comes of a look at the post What are the main…
-
2
votes3
answers1629
viewsA: Problems trying to create a virtual environment with pipenv
There is a question similar to yours on Soen. There it is raised that maybe you have a broken installation of 'Pip' and it is recommended to open Pip and install again. I’m not a big fan of that…
-
0
votes1
answer133
viewsA: APÍ Django-storages Dropbox url error Pattern
Personally I think dealing with the static files in the production environment is one of the most complicated things. As the own documentation says: Of course, like all deployment tasks, the…
-
1
votes1
answer68
viewsA: Searching for a field contained in several models
To be able to filter efficiently you have to pass the resulting object of your search as context to your view. py views. def getdb(request): _tags = request.GET.get('search') if _tags: tags =…
-
6
votes2
answers502
viewsA: Is it possible to use dictionaries inside lists in Python?
In your case you would have to go through your list and then the dictionary. Since one is inside the other. In fact the method items() does not work in lists, but there is even the need to have a…
pythonanswered Otávio Reis Perkles 855 -
0
votes1
answer46
viewsA: Foreign key is not printed in table
At the getter where you are defining the relationship between your fields this: @OneToOne public Art getArt() { return art; } When in fact it should be returning a direct reference to the object…
-
4
votes1
answer1333
viewsA: Calculating the execution time of a program
Just use the library time import time tempo_inicial = time.time() funcao() # chame a função que deseja medir o tempo de execução aqui print("--- %s segundos ---" % (time.time() - tempo_inicial))…
pythonanswered Otávio Reis Perkles 855 -
2
votes3
answers4127
viewsA: Calling attributes of an object in another class in python
Note the following example: example.py class Pessoa: def __init__(self, nome, idade): self.nome = nome self.idade = idade def setNome(self, nome): self.nome = nome def setIdade(self, idade):…
-
0
votes1
answer190
viewsA: python : Wait event on keyboard, with minimized script?
As stated earlier, you can use the library Pyhook that monitors user activity through your keyboard or mouse inputs. I bumped into a video which shows an effective example of saving keyboard inputs…
-
2
votes1
answer271
viewsA: Maximum number of lines recommended
The PEP8 is the most followed and well accepted best practice guide within python, in which you find several 'conventions' for writing your code. Splitting your module into other smaller modules may…
-
1
votes1
answer584
viewsA: Creating Table/BD with Django?
Daniel for your table to be created it is necessary that your app is properly mapped inside your file py Settings. INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth',…
-
2
votes2
answers43
viewsA: Doubt in the logic of the script
Leandro, to understand this script is good to understand how the while loop works. The first while will only run if your condition is met,: while linha <= altura: #linha(1) é de fato menor que…
-
1
votes1
answer164
viewsA: Integrate Python language to websites. How?
A way to use Python for create sites (if that’s what you want, from what I understand of your question) is using Frameworks or micro-Frameworks of the language. A framework is a set of libraries…
-
3
votes2
answers3836
viewsA: How to access variables defined in another function?
When you set a variable within of a function, this variable exists only during the execution time of the function. In order for you to use the values of M1 or m2, they should be global variables, or…
pythonanswered Otávio Reis Perkles 855 -
4
votes2
answers2562
viewsA: Static files on Django
The first thing to do is to check the PATH of your static files, or wherever you are sending them. py Settings. STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static'), ] This…
-
2
votes1
answer31
viewsA: Pq shows this strange result when printing the values defined in class ? (Python)
Let’s take a step by step look at your code: class Car(object): condition = "new" def __init__(self, model, color, mpg): self.model = model self.color = color self.mpg = mpg You own a class that…
-
1
votes2
answers247
viewsA: Python module usage in Django
Since Django is a python framework, the modules developed for Python are perfectly usable within Django. An illustrative example would be: py views. from django.shortcuts import render #Importação…
-
1
votes1
answer806
viewsA: Python replaces only PHP or replaces PHP and apache?
In the Django (the most widespread python web framework) runs a server under the table to make it easier to write your application. This server runs on the development environment, i.e.: On your…
-
1
votes2
answers3598
viewsQ: Images with Django - exhibition and Static
I’m a beginner in Django and I’m developing a simple blog. I know that the configuration of static files needs to be different for the development and production environment, but I always get caught…
-
1
votes2
answers7513
viewsA: How can I use the results of one function within another in python
Your python algorithm has some logic errors. starting with the function name_name(): def preencher_nome(): lista = [] contador = len(lista) while contador <= 9: lista.append(str(input("Digite o…
-
0
votes3
answers12022
viewsA: Read 10 whole numbers and get the biggest one among them
You could do it that way: cont = 0 lista_numeros =[] while cont != 10: #Para poder pegar 10 numeros numero = int(input('Digite um numero: ')) lista_numeros.append(numero) cont = cont + 1 maior =…
-
2
votes2
answers787
viewsA: Syntax error problem in Else python
Arthur, when you come to use the % to mark where Voce wants the value of a certain variable within its print it must follow the following syntax: print('quero falar dessa % variável ' %(variavel))…
python-2.7answered Otávio Reis Perkles 855 -
0
votes1
answer501
viewsA: Legacy of Templates not working
During my researches I realized that this type of error is a recurring thing with respect to the heritage of Templates so I decided to leave here the solution to the problem and if possible…
-
1
votes1
answer501
viewsQ: Legacy of Templates not working
I’m trying to create blocks within my base template (index.html), but apparently the block is not used. index.html {% load static %} <!DOCTYPE html> <html lang="pt-br"> <head>…