7

これはおそらく経験豊富なユーザーには明らかですが、私が Django を扱ってまだ数日しか経っていません。

質問:グローバル ビュー、つまりメイン ページをどこに配置しますか?

pollsというアプリのビューのみを作成するチュートリアルに従いました。また、できるだけ多くのものをデカップリングされたアプリに入れ、移植できるようにする必要があるとも書かれています。メインページのビューについては何も見つかりませんでした。したがって、メインのものをproject_name/project_name/views.pyに配置するか、別のアプリを作成し、ビューをproject_name/globalapp/views.pyに配置してから、'^$' URL をglobal.mainにマップする必要がありますか?

やりたいことは何でもできると思いますが、まだ気付いていない利点があるため、一般的な方法があるのだろうかと思います。

この質問を見つけましたが、これについての答えは明確ではないようです。

4

1 に答える 1

2

This is a matter of personal preference. My own rule-of-thumb is:

If your global pages are simple collections of links to your apps or data from them then the easiest way is to put the views for them in a file at the project level, right next to your settings.py and urls.py. You also put custom middleware and custom context processors in files in the same location.

If your global pages are any more complicated than that (for example they need their own models or forms or ...) then put them in a separate app.

于 2013-01-05T12:20:01.293 に答える