Change to modelform, and the code in views is as follows:
form.instance.comment_man = request.user form.instance.comment_course_id = couseid form.instance.comment_comment = textcontent form.instance.add_time = timezone.now() form.save()
Change to modelform, and the code in views is as follows:
form.instance.comment_man = request.user form.instance.comment_course_id = couseid form.instance.comment_comment = textcontent form.instance.add_time = timezone.now() form.save()
1、 Exception 1: runtimeerror: an attempt has been made to start a new process
Reason: multiple processes need to run in the main function
Solution 1:
Add the main function and call it in main.
if __name__ == '__main__':
main()
Solution 2:
num_workers changed to 0, single process loading
Ers changed to 0, single process loading
Run Django with pycharm, python manage Py runserver error
Checked the Internet and said to put widgets Delete the comma in line 152 of Py, which may be a compatibility problem between Python and Django. Try it. You can click the hyperlink above. Pycharm can quickly open the document, and then find the widgets under admin Py file is OK, because the prompt says form Django contrib. Admin import helpers, widgets, and options The PY file is in the admin directory.
The solution is to use
Python manage py runserver 127.0.0.1:8080
or start the specified network card: python manage.py runserver 192.168.1.248
The main reason is that Django is upgraded or downgraded;
Solution:
1. Delete database content
2、python manage.py makemigrations
3、python manage.py migrate
4、python manage.py createsuperuser
error: (1146, "Table 'mydb.django_session' doesn't exist")
Because there is no Django in the database table_session.
Execute the command at the terminal to migrate the data structure
$ python manage.py migrate
After executing the above command, the output results are all OK. You can see that many tables have been added to the database table, The details are as follows
# By default 10 tables are automatically created in our database, as follows.
MariaDB [mydemo]> show tables;
+----------------------------+
| Tables_in_mydemo |
+----------------------------+
| auth_group |
| auth_group_permissions |
| auth_permission |
| auth_user |
| auth_user_groups |
| auth_user_user_permissions |
| django_admin_log |
| django_content_type |
| django_migrations |
| django_session |
| stu |
+----------------------------+
11 rows in set (0.00 sec)
Then it was solved
Execute command Python manage.py startapp Myjango
App reports an error: file “manage. Py”, line 16) from exc ^ syntax error: invalid syntax
reason:
Python 3 is installed, but Python is used for execution
solve:
Change Python to python3 and execute the above command
python3 manage.py startapp myjango
The object of set is irreversible
I am adding an error in the path of the form, and then checking URLs
it is found that when the app configures URLs, the [] of URL patterns is written as {}
URL patterns should be a list[].
Then there’s no problem~
1. Background
Because you want to change the default database of Django to MySQL, the following error is reported when starting the project
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
2. Solution
From the above results, it can be seen that the corresponding module cannot be identified, so the corresponding module needs to be modified __ init__.Py file
import pymysql
pymysql.install_as_MySQLdb()
Just start the service again
Resolution of internal server error problem in diango project
Project scenario:
Django project
using uwsgi deployment
internal server error is found after packaging and running
font>
Problem Description:
internal server error appears on the website of the project. Check the log and find no Python application found
font>
Solution:
Delete uwsgi_ Log restart uwsgi open the uwsgi log file and constantly try to modify it. Open the uwsgi log to check the problem
Cause analysis:
the existing problems are as follows: font>
Solution:
1. Questions:
resolvent:
Modify the Django/views/debug.py file as follows: encoding =’utf-8 ‘