Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Summary of errors that are easy to occur in Django2.1 integrated xadmin management background

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "error summary of Django2.1 integrated xadmin management background". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

By default, django has an admin background management module, but it is ugly and the functions are not complete, but the great god has integrated the xadmin background for us, and we can use it. However, django has been upgraded to version 2.1, and xadmin does not seem to be able to keep up with the pace, so in the process of integration, we will fill the hole step by step. This is also a process of learning, encountered mistakes and found the wrong places. Take a look at the latest django upgrades that have been modified, get rid of those, and replace the corresponding errors.

Xadmin source code address: https://github.com/sshwsfc/xadmin

Download and extract:

We are using the xadmin folder, which copies xadmin to the root directory of the project, at the same level as the project.

Install dependent libraries:

Activate the virtual environment of the project, cd to the extracted xadmin-master directory, and run the code

Pip3 install-r requirements.txt

Introduce: in the project settings.py settings file:

Set in the urls.py of the project

Then run: python manage.py makemigrations to set up the database migration file

At this time, it will lead to a series of error tips.

Error 1: the error caused by the associated relationship ForeignKey. Open the model file models.py in the xadmin file, and add on_delete=models.CASCADE wherever the associated relationship fields appear, as shown below:

Error 2: error caused by merge modification of module package name

Error message: ModuleNotFoundError: No module named 'django.core.urlresolvers'

This is because django2.1 changed from django.core.urlresolvers to django.urls.

Then fromdjango.core.urlresolversimportNoReverseMatch,reverse as shown in the figure

Modified to: from django.urls import NoReverseMatch, reverse

Error 3: the following error prompt appears

This is because django2.1.1 's forms form initialization has only one parameter, and modify the forms.Field.__init__ (self, required, widget, label, initial, help_text, * args, * * kwargs) as shown in the figure:

Error 4: ImportError: cannot import name 'login' from' django.contrib.auth.views'

Solution:

# modify from django.contrib.auth.views import loginfrom django.contrib.auth.views import logout# in website.py to from django.contrib.auth import authenticate, login, logout

Error 5: ImportError: cannot import name 'QUERY_TERMS' from' django.db.models.sql.query'

Solution:

# django2.1.1 version modifies from django.db.models.sql.query import LOOKUP_SEP and QUERY_TERMS# in xadmin\ plugins\ filters.py file to from django.db.models.sql.query import LOOKUP_SEP, and Query# modifies from django.db.models.sql.query import LOOKUP_SEP and QUERY_TERMS# to: from django.db.models.sql.query import LOOKUP_SEPfrom django.db.models.sql.constants import QUERY_TERMS in Django2.0 version

Error 6: ModuleNotFoundError: No module named 'django.contrib.formtools' import fromtools error, version is too low

Solution:

# Uninstall old version of pip uninstall django-formtools# and install new version of pip install django-formtools

Error 7:

Solution:

# modify the from django.contrib.auth.views import password_reset_confirm in xadmin\ plugins\ password.py to: from django.contrib.auth.views import PasswordResetConfirmView

Then change the password_reset_confirm after line 75 return to PasswordResetConfirmView, as shown in the following figure

Error 8: AttributeError: 'Settings' object has no attribute' MIDDLEWARE_CLASSES'

Solution:

# modify the if settings.LANGUAGES and 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE_CLASSES: in xadmin\ plugins\ language.py to: if settings.LANGUAGES and' django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE:

Finally run: python manage.py makemigrations creates the migration data file

Run again: python manage.py migrate migrates the database

If a similar error occurs in the above process, please correct it accordingly. The order of the error prompt may be different, but please read the error prompt code carefully.

This is the end of the content of "error summary of Django2.1 integrated xadmin management background". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report