Your indentation is goofed, and you've mixed tabs and spaces. Run the script with python -tt to verify.
Your indentation is goofed, and you've mixed tabs and spaces. Run the script with python -tt to verify.
If you’re using python 3+ this may also occur if you’re using private variables that start with double underscore, e.g., self.__yourvariable. Just something to take note of for some of you who may run into this issue.
Error 'Event' object has no attribute 'get'
python - object has no attribute get - Stack Overflow
AttributeError: 'Model' object has no attribute 'get'
python 3.x - 'AttributeError' : Object has no attribute 'get' - Stack Overflow
Videos
Your problem is here:
intention = Intention.objects.get(pk=id)
form = IntentionForm(intention) # An unbound form
The first argument to a form is the data but you are passing the instance. To properly pass the instance you should use:
intention = Intention.objects.get(pk=id)
form = IntentionForm(instance=intention) # An unbound form
The above answer is correct, however, this error can also be generated by incorrectly passing arguments in the init of a form, which is used for an admin model.
Example:
class MyForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(self, *args, **kwargs)
Notice the double passing of self? It should be:
class MyForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
Hi. I have this problem "AttributeError at /Post/ 'Post' object has no attribute 'get'"
and have no clue why it happens. I am using a django filter and it's my first time trying "foreignkey"
There are two simple models and Post_price is the one that has a foreignkey attribute.
Thank you for your help in advance.
<These are the models.py files>
class Post(models.Model):
name= models.CharField(max_length=11,default='')
class Post_price(models.Model):
post= models.ForeignKey('Post', blank=True, null=True, on_delete=models.SET_NULL)
content= models.IntegerField(default='')
<it's a django filter file>
class PostFilter(django_filters.FilterSet):
class Meta:
model = Post
fields = {
'name': ...(I just handled it well)
<This one is for views.py>
def Post(request):
s = Post.objects.all()
aq = PostFilter(request.GET, queryset=s)
return render(request,'app/Post.html',{'s':aq})
<just in case urls.py's path part>
path('Post/',Post,name='Post'),
Your function definition def Post(request): overwrites from .models import Post. You need to be more careful with how you write your variables & function/class definitions.
You might want to rename your variables/functions/classes so they’re easier to read and understand, and to avoid collisions.
hello, i am working on a game using pygame and i am going for an OOP approach, the files are pretty big, i will post only a portion of the code; also i am using pycharm so i know for a fact my identation, typing are alright.. plus i have been coding in python for a while now but i just can't grasp onto this issue :(, so far in the game i am just in the main menu phase and whenever i try to run my code i get an error that my game object (which has a reference to another class including the main menu game loop) has no attribute ''screenWidth'' but it actually does have a variable for my screen.. i just use it in the main menu to set another midWidth variable half of that variable as value
here is the code:
main.py
from game import Game
myGame = Game()
while myGame.running:
myGame.currentMenu.drawMainMenu()
myGame.gameLoop()game.py
import pygame
from menu import MainMenu
class Game:
def __init__(self):
pygame.init()
self.running, self.playing = True, False
self.upKey, self.downKey, self.selectKey, self.backKey = False, False, False, False
self.currentMenu = MainMenu(self)
self.screenWidth = 1280
self.screenHeight = 720
self.gameWindow = pygame.display.set_mode((self.screenWidth, self.screenHeight))
pygame.display.set_caption("Game Prototype")
self.backgroundImage = pygame.image.load('Assets/Images/bg_greek.jpg')
self.backgroundImage = pygame.transform.scale(self.backgroundImage, (1920, 1080))
def gameLoop(self):
while self.playing:
self.checkEvents()
if self.selectKey:
self.playing = False
self.gameWindow.blit(self.backgroundImage, (-600, -300))
pygame.display.flip()
self.resetKeys()
menu.py
import pygame
class Menu:
def __init__(self, game):
self.gameClass = game
self.midWidth = self.gameClass.screenWidth / 2
self.midHeight = self.gameClass.screenHeight / 2
self.showMenu = True
self.selectionX, self.selectionY = 0, 0
def drawSelection(self):
selectSurface = pygame.Surface((260, 100), pygame.SRCALPHA)
selectSurface.fill((50, 50, 50, 175))
selectRect = selectSurface.get_rect()
selectRect.center = (self.selectionX, self.selectionY)
self.gameClass.gameWindow.blit(selectSurface, selectRect)
class MainMenu(Menu):
def __init__(self, game):
Menu.__init__(self, game)
self.hoveredState = "Start"
self.startX, self.startY = self.midWidth, self.midHeight
self.optionsX, self.optionsY = self.midWidth, self.midHeight + 100
self.creditsX, self.creditsY = self.midWidth, self.midHeight + 200
self.quitX, self.quitY = self.midWidth, self.midHeight + 300
self.selectionX, self.selectionY = self.startX, self.startY
def drawMainMenu(self):
self.showMenu = True
while self.showMenu:
self.gameClass.checkEvents()
self.checkInput()
self.gameClass.gameWindow.blit(self.gameClass.backgroundImage, (-600, -300))
self.drawSelection()
self.gameClass.drawText("Play", 72, self.startX, self.startY)
self.gameClass.drawText("Options", 72, self.optionsX, self.optionsY)
self.gameClass.drawText("Credits", 72, self.creditsX, self.creditsY)
self.gameClass.drawText("Quit", 72, self.quitX, self.quitY)
pygame.display.flip()
self.gameClass.resetKeys()
it is not complete though
Here is the error:
File "c:\Users\(MY NAME)\OneDrive\Code\(MY NAME).py", line 38, in verify_license_key
url = f"https://api.gumroad.com/v2/licenses/verify?product_permalink=ewaqb&license_key={user_license_key.get()}&increment_uses_count=true"
AttributeError: 'NoneType' object has no attribute 'get'
im getting the the error for the tenth line of code when im trying to use the .get method of a tkinter Entry
code: https://pastebin.com/G6v1nzBj
Also not sure if this is anything but the code works fine on my laptop (i think) but isnt working on my desktop