Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialnakalkucing
12,964 PointsHelp Pleeezzzz! I think I've been staring at this too long. SyntaxError: positional argument follows keyword argument
Build a Social Network with Flask course: video Post Model
When I try running app.py, the console keeps returning:
Traceback (most recent call last):
File "app.py", line 6, in <module>
import forms
File "/home/treehouse/workspace/forms.py", line 6, in <module>
from models import User
File "/home/treehouse/workspace/models.py", line 45
rel_model-'posts'
^
SyntaxError: positional argument follows keyword argument
Any help would be much appreciated!
nakalkucing
12,964 PointsThanks Steven Parker for explaining! I have now provided a link to a snapshot. :)
2 Answers
adrian miranda
13,561 PointsI think you want to change:
related_name-'posts'
to:
related_name='posts'
Also, a little later you say:
order_by - ('-timestamp',)
Again, I think you want to change the dash to an equals sign:
order_by = ('-timestamp',)
nakalkucing
12,964 PointsThank you, adrian miranda! That fixed my issue. :) Thanks again!
adrian miranda
13,561 PointsIt is not clear what you are trying to do, so I will have to guess. Apologies if I guess wrong
Your code says:
user = ForeignKeyField(
model=User,
rel_model-'posts'
)
ForeignKeyField is apparently a function or method call. The first argument you give it is in the form model=User
. That means to tell the ForeignKeyField call you have an argument called model, and it will then look for a variable/function/whatever named User to hand in. I'm not sure that is what you intended. Perhaps you meant to call it with Model
which was the argument given to the surrounding function?
Your second argument is rel_model-'posts'
this appears to mean, a variable called rel_model
from which you are going to subtract a string called 'posts'
Is that really what you intended? If you wanted to stick a couple strings together, you could a plus sign, like rel_model + '-posts'. But it's not clear what you are intending.
The reason it is complaining is that the first argument to ForeignKeyField is in the form name=value
. This is called a keyword argument, because you gave it a keyword, in this case model
. Again I'm not quite sure that is what you intended. But if it was, you cannot follow it with an argument that does not have a keyword.
nakalkucing
12,964 PointsHi adrian miranda! Thanks for your time. Sorry to throw off your answer, but I was careless. :( When I made some changes to my code while trying to fix my problem, I changed some names and forgot to correct them before I took the screenshot. Really sorry. I have now corrected my screenshot and the code you referenced reads like below:
user = ForeignKeyField(
rel_model=User,
related_name-'posts'
)
I don't know how much this affects your answer, and how many of your questions still apply.
I am still receiving the same error and any more help you'd be willing to offer would be appreciated. Thanks again! :)
Steven Parker
231,236 PointsSteven Parker
231,236 PointsYou can't share a direct URL to your workspace, it's temporary and only exists while you are using it.
But you can use the snapshot function in the workspace and provide the link to that.