Question

I am creating a basic blog with only basic python and the taggit module, it resides at http://127.0.0.1:8000/ (have to put random spaces in so i can submit) when i run ./manage.py syncdb it executes correctly and when i runserver it returns no erros. The problem is when i actually visit the website. Than this happens...

SyntaxError at /
invalid syntax (admin.py, line 4)

This is displayed in the webbrowser..

Here is the traceback:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/

Django Version: 1.4.1
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'taggit',
 'MainBlog')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
  101.                             request.path_info)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py" in resolve
  298.             for pattern in self.url_patterns:
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py" in url_patterns
  328.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Library/Python/2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
  323.             self._urlconf_module = import_module(self.urlconf_name)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/Users/zackbaker/MyBlog/MyBlog/urls.py" in <module>
  5. admin.autodiscover()
File "/Library/Python/2.7/site-packages/django/contrib/admin/__init__.py" in autodiscover
  29.             import_module('%s.admin' % app)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)

Exception Type: SyntaxError at /
Exception Value: invalid syntax (admin.py, line 4)

Anyways any help that could be given would be awesome! Thank you guys so much!!

Was it helpful?

Solution

Line 4 of your admin.py is

from admin.site.register(Post)

This is a Python syntax error. It should be simply

admin.site.register(Post)

which calls the appropriate method to register your Post class with Django's admin site.

Incidentally, the from keyword in Python is used to import something into your current module. You should make sure you have the line

from django.contrib import admin

somewhere in lines 1 through 3 of admin.py (probably line 1!), to make sure admin is defined correctly by the time you get to line 4.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top