Home > Net >  from blog.views import (blog_post_detail_page), SyntaxError: invalid syntax
from blog.views import (blog_post_detail_page), SyntaxError: invalid syntax

Time:09-12

hi I was trying to use run server for my Django app that i have created in my directory that looks like this

I was getting this error during runserver from blog.views import (blog_post_detail_page), SyntaxError: invalid syntax

`

1-try_django *src *blog init.py admin.py app.py models.py test.py views.py *tamplest about.html base.html blog_post_detail.html home.html title .txt *try_django.py init.py setting.py urls.py views.py wsgi.py init.py`

#my views looks like:
from django.shortcuts import render

from .models import BlogPost

def blog_post_detail_page(request):
    obj = BlogPost.objects.get(id=1)
    template_name = 'blog_post_detail.html'
    context = {"object": obj}
    return render(request, template_name, context)

#blog models:
from django.db import models


# Create your models here.
class BlogPost(models.Model):
    title = models.TextField()
    content = models.TextField(null=True, blank=True)

#urls :
from django.contrib import admin
from django.urls import path,re_path
from blog.views import (blog_post_detail_page),
from .views import (
    home_page,about_page,contact_page,example_page)

urlpatterns = [
    path('', home_page),
    path('blog',blog_post_detail_page,name='home'),
    path('page/',about_page),
    path('pages/',about_page),
    re_path(r'^pages?/$',about_page),
    re_path(r'^about/$', about_page),
    path('example/', example_page),
    path('contact/', contact_page),
    path('admin/', admin.site.urls),] 

CodePudding user response:

A Syntax Error usually means that you have a typo. Always firstfully check the line it points to.

from blog.views import (blog_post_detail_page),

In above line you have comma outside tuple. If this is the only thing you are importing from it, then do simple import:

from blog.views import blog_post_detail_page
  • Related