Home > other >  Django 2.0 models didn't find objects properties
Django 2.0 models didn't find objects properties

Time:09-20

Novice, please guide
Environment, Windows 7, python36 django2.0.1, model following

View the following

Page below

Web page display is unable to get the information of id of 2, you can connect to the database in the view, is effective on database operations, speculated that the problem is
List=chengyuans. Objects. The get (id='2') this sentence, the object is not selected from the drop-down list of chengyuans, and because they have no, also check for a long time, don't know why not, a great god help,,, card for a long time, thank you thank

CodePudding user response:

Database is int id, when you get id=2, not quotes when the string handling
PS. Capitalize the first letter of, this is the default rules

CodePudding user response:

Id change is 2,,, the feeling is objects to the database information, and the class is first letters to uppercase, no one encountered a similar situation?

CodePudding user response:

reference 1st floor envy111 response:
database id set is int, when you get id=2, not quotes when the string handling
PS. Capitalize the first letter of, this is the default rules

Id change is 2,,, the feeling is objects to the database information, and the class is first letters to uppercase, ask for help,,,

CodePudding user response:

reference wangguan0613 reply: 3/f
Quote: refer to 1st floor envy111 response:

Database is int id, when you get id=2, not quotes when the string handling
PS. Capitalize the first letter of, this is the default rules

Is id to 2,,, the feeling is objects to the database information, and the class is first letters to uppercase, ask for help,,,

That you print your objects. All () or something, and see what is the output of the objects, the debug step by step

CodePudding user response:

reference 4 floor envy111 response:
Quote: reference wangguan0613 reply: 3/f

Quote: refer to 1st floor envy111 response:

Database is int id, when you get id=2, not quotes when the string handling
PS. Capitalize the first letter of, this is the default rules

Is id to 2,,, the feeling is objects to the database information, and the class is first letters to uppercase, ask for help,,,

That you print your objects. All () or something, and see what is the output of the objects, the debug step by step to see


Monotonous to return that step, will be submitted to the wrong Chengyuans matching the query does not exist,
List didn't get to the information, didn't quite understand the cause of the error,,

CodePudding user response:

Passing by the great god help ah,,, the card for a long time, quick collapse,

CodePudding user response:

The original poster can't do as a tutorial lu yao? You disorderly written out?
Written in the models. After py the data model to do database synchronization
At the command line operation, appname is you the name of this application, is built when the startapp this directory name
# the manage. Py makemigrations appname
# the manage. Py migrate appname
Such moddels defined in the model in the database to the table, the table name default is projectname_chengyuans

Then in the views. Py beginning to add
The from models import chengyuans
# this step is the key to lead into the data model!!!!!!



CodePudding user response:

The
reference 7 floor xpresslink response:
the original poster will not be able to take a tutorial lu yao? You disorderly written out?
Written in the models. After py the data model to do database synchronization
At the command line operation, appname is you the name of this application, is built when the startapp this directory name
# the manage. Py makemigrations appname
# the manage. Py migrate appname
Such moddels defined in the model in the database to the table, the table name default is projectname_chengyuans

Then in the views. Py beginning to add
The from models import chengyuans
# this step is the key to lead into the data model!!!!!!

Import a datetime
The from the django. HTTP import HttpResponse
The from the django. Shortcuts import the render_to_response
The from mydjangoapp. Models import Chengyuans
The import pymysql
This reference and just screenshot forgot to cut it out, as for the database synchronization, also early synchronization,
Novice, of course, is an example of an online lu, but it is also the same error,

CodePudding user response:

Each great god ah,,,, post can't sink again so that I will reinstall the software,

CodePudding user response:

The list is the key word, don't be used as a variable name

CodePudding user response:


Install pylint - django using PIP as follows

PIP install pylint - django
Then in the Visual Studio Code goto: User Settings (Ctrl +, or the File & gt; The Preferences & gt; Settings if available) the Put in the following (both please note the curly braces which are required for the custom user Settings in VSC) :

{" python. Linting. PylintArgs ":
"- the load - plugins=pylint_django"
],}


http://cache.baiducontent.com/c? M=9 d78d513d9921ffc19ac837e7c01d7170e55f0207b8091532489cf5f921401120671e3ca7b7f0704a2982c3f56fe0f1dfdf0472d605c70e0dbdccf0a83b4c86e69ca6623716f9b5c53954afe921b619660c404b4ea0ee7cda16fccb39194881515910e593b9df68c590113ca6bf10960bdf5d809025f66e0be7172ff2f2b74882336eb17a1b763284696f6ab031b9c7a8721 & amp; P=9 b769a47cd9a16e908e2977f0c0097 & amp; Newp=9 f769a4786cc42ae59bbca0c504e9f231610db2151d7d6116b82c825d7331b001c3bbfb423261701d9ce7d6502a44b5ae9f33776330523a3dda5c91d9fb4c57479 & amp; User=baidu& FM=sc& Query=Class + % 27 questionhas + no + objects + 60 member % & amp; Qid=9 a55986e00122a2a & amp; P1=1

CodePudding user response:

Suggestions:
1, django will automatically handle ID primary key, so don't need to write in the models and ID
2, class needs to use camel naming rules
3, the list is a standard function, avoid to use standard function name to do variable

CodePudding user response:

Objects in the class to add=models. The Manager ()

CodePudding user response:

nullnullnullnullnullnullnullnullnull
  • Related