How do I customize the admin page in Django 1.7? - django

I've been learning from the Django Documentation and have stumbled upon a road block in the section: https://docs.djangoproject.com/en/1.7/intro/tutorial02/#customize-the-admin-look-and-feel
My files are arranged as:
mysite/
mysite/
__pycache__/
...
__init__.py
settings.py
urls.py
wsgi.py
polls/
__pycache__/
...
migrations/
...
__init__.py
admin.py
models.py
tests.py
views.py
templates/
admin/
base_site.html
db.sqlite3
manage.py
I have modified the text in the file base_site.html to "Polls App" but the admin site continues to display "Django Administration".
PS: I'm using Win8

You need to place that templates folder in the project directory, not on the same level as the project as it currently is.
So place it under mysite/templates and you should be close.
EDIT: Actually, put the templates folder under your application so that it is Polls/templates

I have it at the same place as you, right under the project root. Make sure that django.contrib.admin is defined before your polls app in INSTALLED_APPS.

Related

Django template namespace

I read that for every app of my INSTALLED_APPS in settings.py, Django will look for HTML templates inside the templates subdirectory. But I'm a little confused.
For instance, when creating my HTML templates in the initial project below:
myproject/
manage.py
myapp/
__init__.py
settings.py
urls.py
wsgi.py
templates/
Should I simply create a template subdirectory within the myapp directory and put all my HTML templates inside?
Almost correct, the templates subdirectory within myapp also needs myapp subdirectory which will contain all of your app html files. Also do not mix core project files such as settings.py and wsgi.py within app, better separate them out, hence the better structure would be:
myproject/
manage.py
mysite/
__init__.py
settings.py
wsgi.py
myapp/
__init__.py
urls.py
views.py
templates/myapp/

Where should i put django application folder

I have followed several django tutorials on the web.
There is 2 folders: One for django project and another for application. We can have multiple applications for the same project but i my case, i have just one.
Sometimes, the application folder is located at the same level than project folder and sometimes, the application folder is located inside project folder.
I do not know what is the best solution... It works in both case. It is just a state of the art question
Thanks
Mostly it is a matter of choice and the organization of your Project. Even thought, i will post you here a recomented layout and good reasons to choose this
myproject/
manage.py
myproject/
__init__.py
urls.py
wsgi.py
settings/
__init__.py
base.py
dev.py
prod.py
blog/
__init__.py
models.py
managers.py
views.py
urls.py
templates/
blog/
base.html
list.html
detail.html
static/
…
tests/
__init__.py
test_models.py
test_managers.py
test_views.py
users/
__init__.py
models.py
views.py
urls.py
templates/
users/
base.html
list.html
detail.html
static/
…
tests/
__init__.py
test_models.py
test_views.py
static/
css/
…
js/
…
templates/
base.html
index.html
requirements/
base.txt
dev.txt
test.txt
prod.txt
Allows you to pick up, repackage, and reuse individual Django applications for use in other projects
Environment specific settings. This allows to easily see which settings are shared and what is overridden on a per environment basis.
Environment specific PIP requirements
Environment specific PIP requirements
Small more specific test files which are easier to read and understand.

django cannot import name patterns on app engine as app is working fine on heroku but not working on app engine

I am learning django and i have deployed it on heroku it is working fine here it is the link http://whispering-bayou-9769.herokuapp.com/ but on app engine it is not working giving me error
500 please try again in few time
it is the url for app engine http://djangocomment.appspot.com/
Please help me i think it may be problem of app.yml because on app engine logs there is log telling me error
'exceptions.ImportError'>: cannot import name pattern i have check url.py it is fine already working on heroku
in app.yml i have wriiten
application: djangocomment
runtime: python
version: 1
api_version: 1
handlers:
- url: .*
script: /post/urls.py
env_variables:
DJANGO_SETTINGS_MODULE: 'post.settings'
urls.p[y in post folder contain the path
file structure
app/
build/
categopry/
admin.py
templates/
models.py
urls.py
tests.py
post/
urls.py
forms.py
settings.py
wsgi.py
static/
admin.py
templates/
models.py
urls.py
tests.py
template/
registration/
userprofile/
admin.py
templates/
models.py
urls.py
tests.py
app.yml
manage.py
procfile
README.md
requiremtn.txt
That really isn't how you run a Django app on GAE. What gave you the idea to point the script to urls.py?
For a start, you need to reference Django in the libraries setting in your app.yaml. Then, you need to set the script to the WSGI object within your project's wsgi.py file: perhaps something like post.wsgi.app. See the documentation.

Django directory structure?

I would like to implement a simple queueing service specific to a project. Where should the code go into in the Django directory structure?
Currently the structure is:
sound/
__init__.py
models.py
tests.py
views.py
static
[edit] I am asking where to place the queue service code I created within the direcotry structure above. Should I create a new directory?
Common structures
In Django 1.4+
project_root/
project_name/
media/
static/
some_app/css/app.css # overriding an app css file from project level
css/
project.css
static_root/ # in production using the collectstatic command
templates/some_app/foo.html # overriding some_app at project level
/admin/some_app/some_model/change_list.html
# overriding admin changelist for some_app.models.some_model
settings/
__init__.py
base.py # settings common to all instances of the project
dev.py
staging.py
test.py
prod.py
urls.py
some_app/
static/
css/
app.css
templates/some_app/foo.html
urls.py
views.py
models.py
manage.py
In Django 1.3 and prior
project_root/
some_app/
templates/some_app/foo.html
static/
css/
app.css
urls.py
views.py
models.py
media/
static/
some_app/
css/
app.css # overriding an app css file from project level
css/
project.css
static_root/ (in production)
templates/some_app/foo.html # overriding some_app at project level
/admin/some_app/some_model/change_list.html
# overriding admin changelist for some_app.models.some_model
settings/
__init__.py
base.py # settings common to all instances of the project
dev.py
staging.py
test.py
prod.py
urls.py
manage.py
Alternative approach
project_root/
.gitignore
README.md
docs/
venv/
src/
main/
media/
static/
some_app/css/app.css # overriding an app css file from project level
css/
project.css
static_root/ # in production using the collectstatic command
templates/some_app/foo.html # overriding some_app at project level
/admin/some_app/some_model/change_list.html
# overriding admin changelist for some_app.models.some_model
settings/
__init__.py
base.py
dev.py
staging.py
test.py
prod.py
urls.py
some_app/
static/
css/
app.css
templates/some_app/foo.html
urls.py
views.py
models.py
manage.py
wsgi.py
If you need to use the database, you should add the data models to models.py. For your program I recommend writing it in new python files (e.g. queuing.py) that you would import when and where you want to use it.
You could create another django app just for this as well.

Where should i create django apps in django 1.4?

I've just started a new project in django 1.4 and since they've changed the default layout for manage.py and the whole folder hierarchy (see https://docs.djangoproject.com/en/dev/releases/1.4/#updated-default-project-layout-and-manage-py) i cannot decide where should i put my app packages - inside mysite or outside it? What's the best practice? For some reason, startapp command creates the app outside of the mysite package, but this feels somehow wrong.
So, what's the best? This:
manage.py
mysite/
__init__.py
settings.py
urls.py
myapp/
__init__.py
models.py
or this:
manage.py
myapp/
__init__.py
models.py
mysite/
__init__.py
settings.py
urls.py
?
The second way.
manage.py
myapp/
__init__.py
models.py
mysite/
__init__.py
settings.py
urls.py