FatFrog
FatFrog

Reputation: 13

"return self.title</pre>" returns a syntax error django

Please bear with my ineptitude. I'm trying upgrade my skillset from simple python scripts to something closer to resembling a full stack developer. RN I am creating a simple Django todo app and am going through a basic tutorial here. https://www.geeksforgeeks.org/python-todo-webapp-using-django/

Env is setup with the following...

Python==3.8.9

Django==3.2.9

django-crispy-forms==1.13.0

my models.py looks like this:

from django.db import models
from django.utils import timezone


class Todo(models.Model):
    title = models.CharField(max_length=100)
    details = models.TextField()
    date = models.DateTimeField(default=timezone.now)
, if I am correct in assuming this is related to CSS. 

I am not sure where to go from here. Can anyone help me? 
    def __str__(self):
        return self.title</pre>


and my forms.py looks like this

from django import forms
from .models import Todo


class TodoForm(forms.ModelForm):
    class Meta:
        model = Todo
        fields = "__all__"</pre>

When I execute python3 manage.py makemigrations or runserver I get the following error and am clearly unable to figure out why.

  File "/home/ezurel/Coding/AppleTree/AppleTree/urls.py", line 19, in <module>
    from todone import views
  File "/home/ezurel/Coding/AppleTree/todone/views.py", line 7, in <module>
    from .forms import TodoForm
  File "/home/ezurel/Coding/AppleTree/todone/forms.py", line 8
    fields = "__all__"</pre>
                       ^
SyntaxError: invalid syntax

I'm stumped as to the need for the </pre> tag and to why it needs to be there and not as part of the HTML, if I am correct in assuming this is related to CSS.

I am not sure where to go from here. Can anyone help me?

Upvotes: 1

Views: 82

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 477804

Remove the </pre> tag. This tag was (very) likely used to typeset a code fragment, since code fragments are written between <pre> … </pre>, but it is not valid Python code:

class TodoForm(forms.ModelForm):
    class Meta:
        model = Todo
        fields = "__all__"  # ← no </pre>

and for the model:

class Todo(models.Model):
    title = models.CharField(max_length=100)
    details = models.TextField()
    date = models.DateTimeField(default=timezone.now)
    
    def __str__(self):
        return self.title # ← no </pre>

Upvotes: 1

Related Questions