Giter VIP home page Giter VIP logo

web-development-with-django's Introduction

Web Development with Django

GitHub issues GitHub forks GitHub stars PRs Welcome

This is the repository for Web Development with Django, published by Packt. It contains all the supporting project files necessary to work through the course from start to finish.

Requirements and Setup

Web Development with Django

To get started with the project files, you'll need to:

  1. Install Python
  2. Install PyCharm
  3. Install DB Browser for SQLite

About Web Development with Django

Django is a popular Python-based framework for web application development. Like Python, Django is easy for beginners to learn and enables constant progress. This book will help aspiring web developers gain the skills to use Django to develop robust web apps.

What you will learn

  • Create a new application and add models to describe your data
  • Use views and templates to control behavior and appearance
  • Implement access control through authentication and permissions
  • Develop practical web forms to add features such as file uploads
  • Develop a RESTful API and JavaScript code that communicates with it
  • Connect to a database such as PostgreSQL

Related Workshops and Books

If you've found this repository useful, you might want to check out some of our other workshop titles:

Download a free PDF

If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.

https://packt.link/free-ebook/9781839212505

web-development-with-django's People

Contributors

abhishekr128 avatar ashishjpackt avatar beneboy avatar packt-itservice avatar packtsupport avatar packtutkarshr avatar saumyajha09 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

web-development-with-django's Issues

Chapter 3: Template tags and whitespace control

Template tags like "{% endfor %}" make a newline in HTML. This is against my own HTML-Zen-Rules. Jinjas "{% endfor -%}" dont work in Django. Is there a Zen solution for this problem? "#" or mixed template and html-Tags in one line are not Zen-Solutions.

I want perfect HTML-code. I dont want newlines and I dont wont to break my Zen-Rule of having nice-code.

Chapter 2: Unable to serialize .csv file

Hello, I am working on a windows system and using the newest versions of Pycharm and Django. I am coming across an error in the section of chapter 2 titled: Populating The Bookr Project's Database. From the looks of it, some of the commands used in this section are Linux based (like in step 3 using 'rm' for linux and 'del' for windows). The main issue I am having is on step 5 when you have to execute the 'loadcsv' command to populate the sqlite3 database. I found out that on windows 'loadcsv' needs to be changed to 'loaddata' and the '--csv' argument needs to be removed completely. Every time I change one of these variables I get a step further, but now I am completely stuck when I get this error:

CommandError: Problem installing fixture 'reviews/managment/commands/WebDevWithDjangoData': csv is not a known serialization format.

I am pretty new to the Django framework, so any bit of information helps! Thx!

[Question] Customizing the Admin Interface

In p. 190, it says:

As BookrAdminSite is project-specific, the code does not really belong under our reviews folder.

But in the same page, you then proceed to define the AdminConfig under the reviews folder (reviews/apps.py), which to me seems to conflict the quoted sentence?

What is the reasoning behind defining the AdminSite under Bookr but then having the AdminConfig under the reviews app, which then refers to the bookr.AdminSite? I'm confused whether this was unintentional and it is intended that both should be under bookr/admin.py especially by establishing that BookrAdminSite is project-specific and also since the code doesn't work according to this issue.

from django.contrib import admin
from django.contrib.admin.apps import AdminConfig


class BookrAdminSite(admin.AdminSite):
    title_hader = 'Bookr Admin'
    site_header = 'Bookr administration'
    index_title = 'Bookr site admin'


class BookrAdminConfig(AdminConfig):
    default_site = 'bookr.admin.BookrAdminSite'

[Question] Activity 8.01: book instance is being saved twice if `cover` is provided?

In the section, "Writing PIL images to ImageField", p. 435, it has the comment, "this also saves the model instance"

...
# Save the wrapped image file data with the original name
m.image_field.save(...)
# this also saves the model instance

Does this mean that in the final code for activity 8.01 the model instance is being saved twice if cover image is uploaded?

...
  book.cover.save(cover.name, image_file)
book.save()
...

Will this mean that the cover image will be written to disk twice as well?

Exercise 12.05: Visiting /api/books in browser doesn't return a 401

I have added these two properties in BookViewSet.

    authentication_classes = [authentication.TokenAuthentication]
    # Check to see if the given user has permission to view the data in this model.
    permissions_classes = [permissions.IsAuthenticated]

However, when I visit /api/books in the browser, I don't get a 401 Unauthorized but rather get a 200 OK with the list of books. What am I missing?

You can see my commits (the actual code I have) for ex12.5 in this branch.

Typo on Chapter 18

We have mentioned throughout the book that the Django dev server is not suitable for use in production. [The Dev Server] is not designed to run multiple processes or handle many users, but more importantly, it doesn't run when the DEBUG setting is set to True.

The last word should be False IIUC.

NameError: name 'auth' is not defined after command on page 102 while Migrating the Reviews App

Please excuse me for taking your time but I'm ony learning and this error little bit too much for me for the moment.

After command:
(bookr) raspberry@faust:~/latest$ python manage.py makemigrations reviews

Output was:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/raspberry/.local/share/virtualenvs/bookr-wLkRGqSc/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/raspberry/.local/share/virtualenvs/bookr-wLkRGqSc/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
    django.setup()
  File "/home/raspberry/.local/share/virtualenvs/bookr-wLkRGqSc/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/raspberry/.local/share/virtualenvs/bookr-wLkRGqSc/lib/python3.8/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/home/raspberry/.local/share/virtualenvs/bookr-wLkRGqSc/lib/python3.8/site-packages/django/apps/config.py", line 301, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/raspberry/development/web/bookr/reviews/models.py", line 44, in <module>
    class Review(models.Model):
  File "/home/raspberry/development/web/bookr/reviews/models.py", line 49, in Review
    creator = models.ForeignKey(auth.get_user_model(), on_delete=models.CASCADE)
NameError: name 'auth' is not defined

Activity 4.01 does not work with Django3.2 (as soon as downgrading to Django3.1, it worked)

Given that your book says "While we can never be 100% certain, we are confident that this code will work fine with future versions of Django too." (p.37), I humbly would like to see the workaround code (or explanation of reason why it does not work with Django3.2). I like your book so much.

Thank you. Error code I got with Django3.2 is as follows:


(venv) Path\to\comment8or>python manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner
    self.run()
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Owner\Desktop\comment8or\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\Owner\Desktop\comment8or\venv\lib\site-packages\django\core\management\commands\runserver.py", line 110, in inner_run
    autoreload.raise_last_exception()
  File "C:\Users\Owner\Desktop\comment8or\venv\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception
    raise _exception[1]
  File "C:\Users\Owner\Desktop\comment8or\venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    autoreload.check_errors(django.setup)()
  File "C:\Users\Owner\Desktop\comment8or\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\Owner\Desktop\comment8or\venv\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\Owner\Desktop\comment8or\venv\lib\site-packages\django\apps\registry.py", line 91, in populate
    app_config = AppConfig.create(entry)
  File "C:\Users\Owner\Desktop\comment8or\venv\lib\site-packages\django\apps\config.py", line 149, in create
    raise RuntimeError(
RuntimeError: 'messageboard.apps' declares more than one default AppConfig: 'AdminConfig', 'MessageboardAdminConfig'.


django.urls.exceptions.NoReverseMatch: Reverse for 'publisher_edit' with arguments '(None,)' not found. 1 pattern(s) tried: ['books/publishers/(?P<p_id>[0-9]+)/$']

Hi,
In Chapter07/Exercise7.03/bookr/reviews/views.py I met a problem, namely I got an exception as updated_publisher doesn't have an id ('pk' in this book). My code:
views.py

 if request.method == 'POST':
        form = PublisherForm(request.POST, instance=publisher)
        if form.is_valid():
            updated_publisher = form.save()
            if publisher is None:
                messages.success(request, f'Publisher {updated_publisher} was created.')
            else:
                messages.success(request, f'Publisher {updated_publisher} was updated.')  
          
            return redirect("publisher_edit", updated_publisher.id)

forms.py

class PublisherForm(forms.ModelForm):
    class Meta:
        model = Publisher
        fields = '__all__'

models.py

class Publisher(models.Model):
    id = models.IntegerField(primary_key=True, editable=False)
    name = models.CharField(max_length=64)
    website = models.URLField(help_text="Publisher's website", blank=True)

    def __str__(self):
        return self.name

Yet, if I get a database object and return redirect based on it (the last line of the code), everything works as was intended.

if request.method == 'POST':
        form = PublisherForm(request.POST, instance=publisher)
        if form.is_valid():
            updated_publisher = form.save()
            # get a database obj
            pub = Publisher.objects.get(name=updated_publisher.name)
            if publisher is None:
                messages.success(request, f'Publisher {updated_publisher} was created.')
            else:
                messages.success(request, f'Publisher {updated_publisher} was updated.')  
            # pub - a database obj
            return redirect("publisher_edit", pub.id)

Though there is another problem. If I have more than one Publisher with the same name and try Publisher.objects.get(), I get an error as .get() can retrieve only one object.

I don't know whether the authors are reading issues, yet if they are, it would be nice to get a piece of advice or an explanation how I can get an id value ('pk' in this book).

Thanks!

Activity5.01 logo.png from reviews app

I have checked many items, but the logo with the word reviews isn't loaded in base.html inside reviews app. The image from home page is still the same logo.png in all pages.

project_structure

Also, I tried to change STATICFILES_DIRS in settings.py even using the solution configuration didn't help, neither
STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'reviews/static/') ]
or
STATICFILES_DIRS = [ BASE_DIR / "static", 'reviews/static', # ("reviews", "full_path_to_static_folder") ]

Working on chapter 9 ERROR: Reverse for 'index' not found. 'index' is not a valid view function or pattern name.

So I am working through chpt. 9 everything is going fine. Until I get to the exercise about making the logout page work. So after following exercise 9.04 I click to logout and get this error.

Reverse for 'index' not found. 'index' is not a valid view function or pattern name.

Error during template rendering
In template C:\Users\jlow\django\bookr2\templates\base.html, error at line 7

Reverse for 'index' not found. 'index' is not a valid view function or pattern name.

Here is line 7 from base.html

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

Now I can get it to display the admin logout page if I move the registration templates folder to bookr/reviews/templates/registration. everything else seems to still work fine but the logout page is still the admin one. This was how I originally had this setup because it seemed like that was where the author wanted me to put it. Anyway after looking over the files on github I realized I had placed the registration templates folder in the wrong templates folder and I moved it to the correct one. But now when I click logout I get the error. I have compared pretty much all my files to the ones here on github and they are pretty much the same. I have even gone as far as to copy and paste from github into my project and still get the same error. The only way I have been able to see it work correctly is by downloading the files from github and running the project from them. I am at a total loss here and I know its got to be something stupid I did to get this to happen. If anyone would like to see some of my files from the project please let me know which ones and I will put them here.

Ex18.3, step 10: error when migrating, "...module 'bookr.settings' has no attribute 'Prod"

Here is the shell output starting at moving the bookr folder to /home/bookr, with some commands to show my directory structure, etc.

pax@bookr:~$ ls
bookr
pax@bookr:~$ ls bookr
book_management  filter_demo      production.conf.sample  static
bookr            manage.py        requirements.txt        templates
bookr_admin      media            reviews
db.sqlite3       production.conf  session_info.py
pax@bookr:~$ sudo mv bookr /home/bookr/
[sudo] password for pax:
pax@bookr:~$ ls
pax@bookr:~$ ls /home/bookr
bookr
pax@bookr:~$ sudo chown -R bookr:bookr /home/bookr/bookr
pax@bookr:~$ ls -al /home/bookr
total 44
drwxr-xr-x  5 bookr bookr 4096 Oct 20 23:29 .
drwxr-xr-x  4 root  root  4096 Oct 20 07:09 ..
-rw-------  1 bookr bookr 1255 Oct 20 23:27 .bash_history
-rw-r--r--  1 bookr bookr  220 Oct 20 07:09 .bash_logout
-rw-r--r--  1 bookr bookr 3771 Oct 20 07:09 .bashrc
drwxrwxr-x 10 bookr bookr 4096 Oct 20 23:26 bookr
drwxrwxr-x  3 bookr bookr 4096 Oct 20 08:22 .cache
drwxrwxr-x  3 bookr bookr 4096 Oct 20 08:21 .local
-rw-r--r--  1 bookr bookr  807 Oct 20 07:09 .profile
-rw-------  1 bookr bookr 6834 Oct 20 23:18 .viminfo
pax@bookr:~$ ls -al /home/bookr/bookr
total 236
drwxrwxr-x 10 bookr bookr   4096 Oct 20 23:26 .
drwxr-xr-x  5 bookr bookr   4096 Oct 20 23:29 ..
drwxrwxr-x  5 bookr bookr   4096 Oct 20 23:26 book_management
drwxrwxr-x  3 bookr bookr   4096 Oct 20 23:26 bookr
drwxrwxr-x  4 bookr bookr   4096 Oct 20 23:26 bookr_admin
-rw-rw-r--  1 bookr bookr 180224 Oct 20 23:26 db.sqlite3
drwxrwxr-x  6 bookr bookr   4096 Oct 20 23:26 filter_demo
-rw-rw-r--  1 bookr bookr    746 Oct 20 23:26 manage.py
drwxrwxr-x  3 bookr bookr   4096 Oct 20 23:26 media
-rw-rw-r--  1 bookr bookr    293 Oct 20 23:26 production.conf
-rw-rw-r--  1 bookr bookr    272 Oct 20 23:26 production.conf.sample
-rw-rw-r--  1 bookr bookr    289 Oct 20 23:26 requirements.txt
drwxrwxr-x  9 bookr bookr   4096 Oct 20 23:26 reviews
-rw-rw-r--  1 bookr bookr    496 Oct 20 23:26 session_info.py
drwxrwxr-x  2 bookr bookr   4096 Oct 20 23:26 static
drwxrwxr-x  4 bookr bookr   4096 Oct 20 23:26 templates
pax@bookr:~$ sudo chmod 600 /home/bookr/bookr/production.conf
pax@bookr:~$ ls -l /home/bookr/bookr/
total 228
drwxrwxr-x 5 bookr bookr   4096 Oct 20 23:26 book_management
drwxrwxr-x 3 bookr bookr   4096 Oct 20 23:26 bookr
drwxrwxr-x 4 bookr bookr   4096 Oct 20 23:26 bookr_admin
-rw-rw-r-- 1 bookr bookr 180224 Oct 20 23:26 db.sqlite3
drwxrwxr-x 6 bookr bookr   4096 Oct 20 23:26 filter_demo
-rw-rw-r-- 1 bookr bookr    746 Oct 20 23:26 manage.py
drwxrwxr-x 3 bookr bookr   4096 Oct 20 23:26 media
-rw------- 1 bookr bookr    293 Oct 20 23:26 production.conf
-rw-rw-r-- 1 bookr bookr    272 Oct 20 23:26 production.conf.sample
-rw-rw-r-- 1 bookr bookr    289 Oct 20 23:26 requirements.txt
drwxrwxr-x 9 bookr bookr   4096 Oct 20 23:26 reviews
-rw-rw-r-- 1 bookr bookr    496 Oct 20 23:26 session_info.py
drwxrwxr-x 2 bookr bookr   4096 Oct 20 23:26 static
drwxrwxr-x 4 bookr bookr   4096 Oct 20 23:26 templates
pax@bookr:~$ sudo -H -u bookr /bin/bash
bookr@bookr:/home/pax$ cd
bookr@bookr:~$ python3 -m virtualenv --python=python3 bookr-venv
created virtual environment CPython3.8.10.final.0-64 in 450ms
  creator CPython3Posix(dest=/home/bookr/bookr-venv, clear=False, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, pkg_resources=latest, via=copy, app_data_dir=/home/bookr/.local/share/virtualenv/seed-app-data/v1.0.1.debian.1)
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
bookr@bookr:~$ source bookr-venv/bin/activate
(bookr-venv) bookr@bookr:~$ pip3 install -r bookr/requirements.txt
Collecting asgiref==3.2.3
  Downloading asgiref-3.2.3-py2.py3-none-any.whl (18 kB)
Collecting dj-database-url==0.5.0
  Using cached dj_database_url-0.5.0-py2.py3-none-any.whl (5.5 kB)
Collecting Django==3.0.3
  Downloading Django-3.0.3-py3-none-any.whl (7.5 MB)
     |████████████████████████████████| 7.5 MB 9.1 MB/s
Collecting django-configurations==2.2
  Using cached django_configurations-2.2-py2.py3-none-any.whl (16 kB)
Collecting django-crispy-forms==1.8.1
  Downloading django_crispy_forms-1.8.1-py2.py3-none-any.whl (108 kB)
     |████████████████████████████████| 108 kB 5.2 MB/s
Collecting django-debug-toolbar==2.2
  Downloading django_debug_toolbar-2.2-py3-none-any.whl (198 kB)
     |████████████████████████████████| 198 kB 4.0 MB/s
Collecting django-rest-framework==0.1.0
  Downloading django-rest-framework-0.1.0.tar.gz (969 bytes)
Collecting djangorestframework==3.11.0
  Downloading djangorestframework-3.11.0-py3-none-any.whl (911 kB)
     |████████████████████████████████| 911 kB 5.2 MB/s
Collecting Pillow==7.0.0
  Downloading Pillow-7.0.0-cp38-cp38-manylinux1_x86_64.whl (2.1 MB)
     |████████████████████████████████| 2.1 MB 3.9 MB/s
Collecting pytz==2019.3
  Downloading pytz-2019.3-py2.py3-none-any.whl (509 kB)
     |████████████████████████████████| 509 kB 7.5 MB/s
Collecting six==1.14.0
  Downloading six-1.14.0-py2.py3-none-any.whl (10 kB)
Collecting sqlparse==0.3.0
  Downloading sqlparse-0.3.0-py2.py3-none-any.whl (39 kB)
Collecting gunicorn==20.0.4
  Using cached gunicorn-20.0.4-py2.py3-none-any.whl (77 kB)
Processing ./.cache/pip/wheels/35/64/21/9c9e2c1bb9cd6bca3c1b97b955615e37fd309f8e8b0b9fdf1a/psycopg2-2.8.5-cp38-cp38-linux_x86_64.whl
Requirement already satisfied: setuptools>=3.0 in ./bookr-venv/lib/python3.8/site-packages (from gunicorn==20.0.4->-r bookr/requirements.txt (line 13)) (44.0.0)
Building wheels for collected packages: django-rest-framework
  Building wheel for django-rest-framework (setup.py) ... done
  Created wheel for django-rest-framework: filename=django_rest_framework-0.1.0-py3-none-any.whl size=1377 sha256=a09a2f174511c3b1b9889833e1e94c6bbb50ab4906c04420b399d9c5e6b1e8ea
  Stored in directory: /home/bookr/.cache/pip/wheels/5f/6b/cc/126959a66b51f960094ee9ec7c5263d74d91b837341dfd0a59
Successfully built django-rest-framework
Installing collected packages: asgiref, dj-database-url, sqlparse, pytz, Django, six, django-configurations, django-crispy-forms, django-debug-toolbar, djangorestframework, django-rest-framework, Pillow, gunicorn, psycopg2
Successfully installed Django-3.0.3 Pillow-7.0.0 asgiref-3.2.3 dj-database-url-0.5.0 django-configurations-2.2 django-crispy-forms-1.8.1 django-debug-toolbar-2.2 django-rest-framework-0.1.0 djangorestframework-3.11.0 gunicorn-20.0.4 psycopg2-2.8.5 pytz-2019.3 six-1.14.0 sqlparse-0.3.0
(bookr-venv) bookr@bookr:~$ cd bookr
(bookr-venv) bookr@bookr:~/bookr$ export $(cat production.conf | xargs)
(bookr-venv) bookr@bookr:~/bookr$ echo $DJANGO_STATIC_ROOT
/var/www/bookr/static
(bookr-venv) bookr@bookr:~/bookr$ echo $DJANGO_ALLOWED_HOSTS
192.168.1.14
(bookr-venv) bookr@bookr:~/bookr$ python3 manage.py migrate
Traceback (most recent call last):
  File "manage.py", line 24, in <module>
    main()
  File "manage.py", line 20, in main
    execute_from_command_line(sys.argv)
  File "/home/bookr/bookr-venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/bookr/bookr-venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 345, in execute
    settings.INSTALLED_APPS
  File "/home/bookr/bookr-venv/lib/python3.8/site-packages/django/conf/__init__.py", line 76, in __getattr__
    self._setup(name)
  File "/home/bookr/bookr-venv/lib/python3.8/site-packages/django/conf/__init__.py", line 63, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/bookr/bookr-venv/lib/python3.8/site-packages/django/conf/__init__.py", line 142, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible
  File "/home/bookr/bookr-venv/lib/python3.8/site-packages/configurations/importer.py", line 159, in load_module
    reraise(err, "Couldn't find configuration '{0}' "
  File "/home/bookr/bookr-venv/lib/python3.8/site-packages/configurations/importer.py", line 157, in load_module
    cls = getattr(mod, self.name)
' in module 'bookr':  module 'bookr.settings' has no attribute 'Prod
(bookr-venv) bookr@bookr:~/bookr$

Looking at bookr/settings.py, I do have the class Prod

(bookr-venv) bookr@bookr:~/bookr$ cat bookr/settings.py | grep Prod
class Prod(Dev):

I copied all this project's files under Chapter 18 > Exercise 18.3 folder to my repository already. E.g. wsgi.py is the same as mine. Also settings.py is the same.

Any other ideas how to troubleshoot this?

Chapter 4 : ModuleNotFoundError: No module named 'admin'

After following all the steps of the process of creating a custom admin page, I get the following error:

$ python manage.py runserver Watching for file changes with StatReloader Exception in thread django-main-thread: Traceback (most recent call last): File "C:\..\..\..\Python\Django\venv\lib\site-packages\django\utils\module_loading.py", line 44, in autodiscover_modules if register_to: File "C:\..\..\..\Python\Django\venv\lib\site-packages\django\utils\functional.py", line 240, in inner self._setup() File "C:\..\..\..\Python\Django\venv\lib\site-packages\django\contrib\admin\sites.py", line 540, in _setup AdminSiteClass = import_string(apps.get_app_config('admin').default_site) File "C:\..\..\..\Python\Django\venv\lib\site-packages\django\utils\module_loading.py", line 17, in import_string module = import_module(module_path) File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked ModuleNotFoundError: No module named 'admin'

Does anybody know what I'm doing wrong here? I followed the exact same steps and my file structure should be correct.

I did notice that the error only occurs when I try to rename 'django.contrib.admin' to reviews.apps.ReviewsAdminConfigin the settings.py file

When i change it back to 'django.contrib.admin' it suddenly works again, but no custom admin site. :(

I get an error when populating the database with csv file (Chapter 2)

The error is as follows:
UnboundLocalError: local variable 'model_name' referenced before assignment
The error is the output of the command:
python manage.py loadcsv --csv reviews/management/commands/WebDevWithDjangoData.csv
Can someone plz help me figure out what's wrong?

Chapter2 Book model: trying to add a non-nullable field 'publisher' to book without a default

You are trying to add a non-nullable field 'publisher' to book without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
 1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
 2) Quit, and let me add a default in models.py
Select an option: 

I found that I need do add a default value, but if I add one there Django raises an issue about the pk, I just added null=True, and it works fine, is this the solution?(There is no problem in the code, I retyped it a few times, ended jut copying it from github, still the same problem)

Activity 17.1 solution for Glances v3.1.3 with psutil v5.5.1

When I try the solution glances --disable-memswap --theme-white as seen in the pdf I encountered the error unrecognized arguments. The version I have is the following,

pax@bookr:~$ glances -V
Glances v3.1.3 with psutil v5.5.1

I also have the latest Ubuntu live server installed: 20.04.3 LTS

My solution was glances --theme-white --disable-plugin memswap and I think it's correct given the similarity in the screenshot. To figure out the name of the module, I used the argument --modules-list.

Screenshot 2021-10-19 235704

Sharing it here in case someone else encounters this, or to notify authors of the change in case PDF can be updated.

Chapter 8 has incorrect reference to reviews app

In exercise 8.06, it incorrectly mentions the reviews app:

Switch back to PyCharm and open the reviews app's forms.py file.

This should be changed to the media_example app:

Switch back to PyCharm and open the media_example app's forms.py file.

This is supported by the example code that it shared in the exercise:
https://github.com/PacktPublishing/Web-Development-with-Django/blob/master/Chapter08/Exercise8.06/media_project/media_example/forms.py

Source:
https://learning.oreilly.com/library/view/web-development-with/9781839212505/B15509_08_SZ_ePub.xhtml#:-:text=Switch

session_info.py > ValueError: not enough values to unpack (expected 2, got 1)

I have Django 3.1 installed.

$ sqlite3 --version
3.24.0 2018-06-04 14:10:15 95fbac39baaab1c3a84fdfc82ccb7f42398b2e92f18a2a57bce1d4a713cbaapl

$ sqlite3 db.sqlite3 
sqlite> .schema django_session
CREATE TABLE IF NOT EXISTS "django_session" ("session_key" varchar(40) NOT NULL PRIMARY KEY, "session_data" text NOT NULL, "expire_date" datetime NOT NULL);
CREATE INDEX "django_session_expire_date_a5c62663" ON "django_session" ("expire_date");

sqlite> select * from django_session;
biwuogaylo9c5czycs8o2zjbb2phnchw|.eJxVjMsOwiAQRf-FtSHQoTxcuvcbyAwwUjU0Ke3K-O_apAvd3nPOfYmI21rj1ssSpyzOAsTpdyNMj9J2kO_YbrNMc1uXieSuyIN2eZ1zeV4O9--gYq_f2pFCBkdgkgefk9VsRo2YuDCGYC0DZ7JGERvP3lnQYHhAFcKoB5XE-wP8wDgK:1mCUSv:vqqueaEanWKKwm3Lotc_Se3ggAwPCaMcI5UIQ0oWV30|2021-08-21 22:06:49.448416
3p5jh0gty4rop8niv6gnpjxz0z2tvzv8|.eJxVjMsOwiAQRf-FtSHQoTxcuvcbyAwwUjU0Ke3K-O_apAvd3nPOfYmI21rj1ssSpyzOAsTpdyNMj9J2kO_YbrNMc1uXieSuyIN2eZ1zeV4O9--gYq_f2pFCBkdgkgefk9VsRo2YuDCGYC0DZ7JGERvP3lnQYHhAFcKoB5XE-wP8wDgK:1mCY1Y:y4_p8IpJ8u2JsphmpF6cjcs0duGOXt47y9LoExbR8QQ|2021-08-22 01:54:48.927927

Using the session_info.py in this repo:

$ python session_info.py 'biwuogaylo9c5czycs8o2zjbb2phnchw|.eJxVjMsOwiAQRf-FtSHQoTxcuvcbyAwwUjU0Ke3K-O_apAvd3nPOfYmI21rj1ssSpyzOAsTpdyNMj9J2kO_YbrNMc1uXieSuyIN2eZ1zeV4O9--gYq_f2pFCBkdgkgefk9VsRo2YuDCGYC0DZ7JGERvP3lnQYHhAFcKoB5XE-wP8wDgK:1mCUSv:vqqueaEanWKKwm3Lotc_Se3ggAwPCaMcI5UIQ0oWV30'
Traceback (most recent call last):
  File "/Users/babysleepapp/Code/_learn/_Books/WebDevWithDjango/bookr/session_info.py", line 16, in <module>
    session_dictionary = get_session_dictionary(session_key)
  File "/Users/babysleepapp/Code/_learn/_Books/WebDevWithDjango/bookr/session_info.py", line 8, in get_session_dictionary
    binary_key, payload = base64.b64decode(session_key).split(b':', 1)
ValueError: not enough values to unpack (expected 2, got 1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.