coding error - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: coding error (/thread-23000.html) Pages:
1
2
|
coding error - bilawal - Dec-06-2019 [/python] class Product(models.Model): description = models.TextField(max_length = 500) ---------------------------- SyntaxError: bad input on line 2 in main.py [/python] RE: coding error - DreamingInsanity - Dec-06-2019 Proper code tags? Full error output in 'error' tags? Is that the full script? There are many reasons you could be getting a 'bad input' error. (remove the slash from the first '[/python]' so it becomes '[python]') RE: coding error - bilawal - Dec-06-2019 class Product(models.Model): description = models.TextField(max_length = 500) RE: coding error - DreamingInsanity - Dec-06-2019 Like this: [ python ] [ /python ] of course, without the spaces. It should look like this if you preview your post: like thisAnd again, is that the full script? What about. the full error? RE: coding error - bilawal - Dec-06-2019 simply compile it it is not compiling its only 2 line code RE: coding error - DreamingInsanity - Dec-06-2019 (Dec-06-2019, 05:42 PM)bilawal Wrote: simply compile itIt won't compile for me because I don't know what 'models' is. It could be library, it could be something else. RE: coding error - bilawal - Dec-06-2019 from django.db import models from django.contrib.auth.models import User from datetime import datetime ##from core.models import Product class Product(models.Model): description = models.TextField(max_length = 500) condition = models.CharField(max_length=100) price = models.DecimalField(max_digits=10,decimal_places=5) created = models.DateTimeField() RE: coding error - DreamingInsanity - Dec-06-2019 Even without the settings file, I cannot reproduce your error. In your code, there was no indentation, but I don't think it would produce that error. Try removing the spaces here: max_length = 500 so it becomes max_length=500
RE: coding error - bilawal - Dec-06-2019 not solved how i gave you for troubleshoot RE: coding error - jefsummers - Dec-06-2019 You're not defining the class properly. You are deriving a new class from models.Model. With no indentation nothing after that is in the class and Python does not like that. If the class is empty, solve by using pass. I don't have those libraries so cannot fully test, so I will make some guesses. from django.db import models from django.contrib.auth.models import User from datetime import datetime ##from core.models import Product class Product(models.Model): pass myProduct = Product() myProduct.description = models.TextField(max_length = 500) myProduct.condition = models.CharField(max_length=100) myProduct.price = models.DecimalField(max_digits=10,decimal_places=5) myProduct.created = models.DateTimeField()Line 7 creates a class description based on models.Model. Line 8 keeps the compiler happy. Line 10 creates an object of type Product. Lines 11-14 set properties of that object. This assumes that models.TextField() exists and has value, which would have to have been set elsewhere in your code. Need clarification if you need more help. |