Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
coding error
#1
[/python]

class Product(models.Model):
description = models.TextField(max_length = 500)

----------------------------
SyntaxError: bad input on line 2 in main.py






[/python]
Reply
#2
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]')
Reply
#3
class Product(models.Model):
description = models.TextField(max_length = 500)
Reply
#4
Like this:
[ python ]
[ /python ]
of course, without the spaces.
It should look like this if you preview your post:
like this
And again, is that the full script?
What about. the full error?
Reply
#5
simply compile it

it is not compiling

its only 2 line code
Reply
#6
(Dec-06-2019, 05:42 PM)bilawal Wrote: simply compile it

it is not compiling

its only 2 line code
It won't compile for me because I don't know what 'models' is.
It could be library, it could be something else.
Reply
#7
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()
Reply
#8
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
Reply
#9
not solved
how i gave you for troubleshoot
Reply
#10
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Coding error. xflyerwdavis 2 521 Oct-07-2023, 07:08 PM
Last Post: deanhystad
  Coding error. Can't open directory EddieG 6 1,108 Jul-13-2023, 06:47 PM
Last Post: deanhystad
  Coding Error EddieG 2 530 Jul-09-2023, 02:59 AM
Last Post: EddieG
  python coding error isntitzee 1 2,202 Oct-17-2020, 06:30 AM
Last Post: buran
  Coding error- Not sure where I have put error markers against the code that is wrong Username9 1 1,725 Sep-28-2020, 07:57 AM
Last Post: buran
  coding error iro a menu Rollo 2 2,081 Sep-27-2020, 04:17 PM
Last Post: deanhystad
  Adafruit LIS3DH coding error FitDad73 1 1,997 Aug-30-2020, 01:37 AM
Last Post: bowlofred
  Coding error- help FatherYeals 3 32,022 Mar-27-2020, 02:11 PM
Last Post: deanhystad
  name undefined Coding Error Ewilliam51 2 2,135 Feb-06-2020, 12:19 AM
Last Post: Ewilliam51
  Pyhton Coding Help Needed (very small error) friduk 2 2,443 Oct-23-2019, 08:41 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020