get_absolute_url
get_absolute_url(), which returns a URL for displaying individual model records on the website (if you define this method then Django will automatically add a "View on Site"button to the model's record editing screens in the Admin site). A typical pattern for get_absolute_url() is shown below.
Of course to make this work you still have to write the URL mapping, view, and template!
def get_absolute_url(self):
"""Returns the url
to access a particular instance of the model."""
return reverse('model-detail-view', args=[str(self.id)])
Note: Assuming you will use URLs like /myapplication/mymodelname/2
to display individual records for your model (where "2"is the id for a particular record), you will need to create a URL mapper to pass the response and id to a "model detail view"(which will do the work required to display the record). The reverse() function above is able to "reverse"your url mapper (in the above case named 'model-detail-view') in order to create a URL of the right format.Of course to make this work you still have to write the URL mapping, view, and template!
Reference
この問題について(get_absolute_url), 我々は、より多くの情報をここで見つけました https://velog.io/@daylee/getabsoluteurlテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol