Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django admin page doesn't show tables of database (djangobook chapter 06)

I am doing the Activating the Admin Interface part in djangobook chapter 06. At the end of that part one has to run the development server and go to http://127.0.0.1:8000/admin/.

However I see this: My Django admin page

Instead of something like this(from the djangobook): How it should look like

This is strange because I have data stored in a table of my mysql database that is linked to my django project in the settings.py file.

This is the DATABASES dictionary in my settings.py file of my django project:

DATABASES = {
    'default': {
        'ENGINE': 'mysql',
        'NAME': 'mydb',                   
        'USER': 'root',                      
        'PASSWORD': 'mypass',                 
        'HOST': 'localhost',                    
        'PORT': '',                      
    }
}

The mysql prompt shows this:

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| mydb               |
+--------------------+
3 rows in set (0.00 sec)

mysql> use mydb;
mysql> show tables;
+----------------------------+
| Tables_in_mydb             |
+----------------------------+
| auth_group                 |
| auth_group_permissions     |
| auth_message               |
| auth_permission            |
| auth_user                  |
| auth_user_groups           |
| auth_user_user_permissions |
| books_author               |
| books_book                 |
| books_book_authors         |
| books_publisher            |
| django_admin_log           |
| django_content_type        |
| django_session             |
+----------------------------+
14 rows in set (0.00 sec)

Why am I not seeing the contents of mydb in my admin page?

Might be relevant:

mysql> select User from mysql.user;
+------------------+
| User             |
+------------------+
| root             |
| debian-sys-maint |
| root             |
| root             |
+------------------+
4 rows in set (0.00 sec)
like image 277
Bentley4 Avatar asked Jul 11 '12 13:07

Bentley4


People also ask

How do I view tables in Django?

If you're interested, run the command-line client for your database and type \dt (PostgreSQL), SHOW TABLES; (MariaDB, MySQL), . tables (SQLite), or SELECT TABLE_NAME FROM USER_TABLES; (Oracle) to display the tables Django created.

Why is my Django admin not working?

'django-admin' is not recognized as an internal or external command, operable program or batch file. To fix this, first close the terminal window and relaunch it with administrator privileges. Once you launch the elevated terminal window change directory to where you wish to start your Django project.

What database does Django admin use?

Django, by default, uses SQLite3 for development. SQLite3 is a simple relational database engine and your database is automatically created as db. sqlite3 the first time you run python manage.py migrate .


1 Answers

You need to keep reading http://django-book.readthedocs.org/en/latest/chapter06.html#adding-your-models-to-the-admin-site

There’s one crucial part we haven’t done yet...
Within the books directory (mysite/books), create a file called admin.py, and type in the following lines of code:

from django.contrib import admin
from mysite.books.models import Publisher, Author, Book

admin.site.register(Publisher)
admin.site.register(Author)
admin.site.register(Book)
like image 51
Mark Lavin Avatar answered Sep 22 '22 17:09

Mark Lavin