At present, there are many AI assistants, and they are all very vague. They share a few commonly used ones such as poe.com, claude, and chathub Google plug-ins.
With so many little assistants, I personally think that prompt is very important. Learning how to use it is the key. The
following is an example of my program writing:
If you are a senior python development engineer, design a small program based on the django framework.
1. Log in to mysql and execute sql, and then display the query results.
2. Design three buttons to display the query sql results, export the current query results to csv, and then provide a download page, that is, the three buttons display 3
, The front-end is mainly simple and practical (refer to bootstrap)
, but it requires multiple corrections and verifications, and it may not be completed in one go.
Finished product:
The following is the error report of the scene:
these three types of error reports are:
-
ModuleNotFoundError: No module named 'mysql'
: This error is caused byviews.py
importingmysql.connector
the module in but not installing it. You need to usepip
the installationmysql-connector-python
module, which can be installed by running the following command in the terminal:pip install mysql-connector-python
-
NameError: name 'os' is not defined
: This error is because the modulesettings.py
is used in or other filesos
, butos
the module is not imported. You need to add the following import statements in the relevant files:import os
-
django.db.utils.NotSupportedError: MySQL 8 or later is required (found 5.6.51)
: This error is because your Django project requires MySQL 8 or higher, but MySQL 5.6.51 is installed on your system. You can try upgrading MySQL to version 8 or higher to solve this problem.
tree:
These files are the core components in the Django framework, each playing different roles:
-
models.py
:- In Django,
models.py
a file defines the database model (Model), that is, the structure and fields of the database table. - By defining model classes and fields, Django can automatically generate the corresponding database table structure and provide a convenient API for interacting with the database.
- Model classes usually inherit from
django.db.models.Model
, and each class's attributes correspond to a field in the database table.
- In Django,
-
settings.py
:settings.py
The file contains the settings and configuration information for the Django project.- In this file, you can configure database connections, static file paths, internationalization settings, middleware, application lists, etc.
- Modifications
settings.py
can affect the behavior and functionality of the entire Django project.
-
urls.py
:urls.py
The file defines a URL routing map that associates URLs with corresponding view functions.- Django's URL routing system will call the corresponding view function according to the URL requested by the user to handle the request.
- In
urls.py
, you can define URL patterns and configure the mapping between URLs and view functions.
-
views.py
:views.py
The file contains the view functions in the Django project.- View functions handle user requests, perform data processing, call models, render templates, etc., and then return the results to the user.
- View functions usually receive user request objects (such as HttpRequest) and return an HttpResponse object.
In summary, models.py
define the database model, settings.py
configure project settings, urls.py
define URL mapping, views.py
handle user requests and data processing. Together, these four files form the core functionality and architecture of the Django project.
Summary: It is a very good learning aid and can also be used as a search engine, but you need to make your own judgment or make more comparisons. Until you find the best and most correct answer