[/python]
class Product(models.Model):
description = models.TextField(max_length = 500)
----------------------------
SyntaxError: bad input on line 2 in main.py
[/python]
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]')
class Product(models.Model):
description = models.TextField(max_length = 500)
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?
simply compile it
it is not compiling
its only 2 line code
(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.
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()
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
not solved
how i gave you for troubleshoot
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.