Django and admin templates - django

I have created a Django project and packaged it using py2exe. It also uses cherrypy as a webserver for the project to get served. I would like to ask a question. My executable django app can't find the admin templates. So i was wondering how does Django locate the admin templates? Do i need to copy them from django/contrib/admin/templates to my templates folder?
The error i get when i execute (using the derived exe) my programm is
TemplateDoesNotExist
Exception Value:admin/login.html django
that is when i visit the admin backend of my project. If i run it normaly through manage.py
admin works fine.

The admin templates are located in django\contrib\admin\templates - you'll have to include them or copy them as is to a template folder in your main app.
An other option would be to put them in a seperate dierctory and add this directory to TEMPLATE_DIRS in your settings.py. This might be a good option for you because it keeps the original files separated from your project templates.

Related

Mezzanine Static files not serving from STATIC_ROOT

I am new to Mezzanine and not an expert in Django. I am trying to make changes in the default Mezzanine theme. I am doing these steps to override default Mezzanine theme,
python manage.py collectstatic
A new static folder is created which stores all the static files across the project in this folder (STATIC_ROOT). This includes Mezzanine default static files as well from virtualenv/lib/python2.7/site-packages/mezzanine/core/static/
Then I run
python manage.py collecttemplates
A new templates folder is created which stores all the templates across the project in this folder.
Now when I make changes in files from /templates directory I get to see those changes in development server.
but when I make changes in /static directory files I do not see those changes in development server.
to make changes to css files I have to go to
virtualenv/lib/python2.7/site-packages/mezzanine/core/static/ path and then only I can see the changes in development server.
I want to know what am I doing wrong. I do not want to make changes in mezzanine css files, I want to overwrite them form static_root.
In mezzanine and in django sites in general, you should not edit files in the /static folder directly since these will be overwritten each time you use the collectstatic command.
Each of the templates Mezzanine provides can be found in the templates directory of each Django app that Mezzanine is comprised of. E.g the base template in mezzanine/core/templates/base.html.
To edit the templates you’d like to modify, copy them into your project’s templates directory and modify them there. You can also use the collecttemplates command to copy templates over automatically. Run python manage.py collecttemplates --help for more info.
The mezzanine template lookup system is described here. This post may also be useful
OKay, After some research I realized, This is not the way to overwrite templates. You want to copy static folder from Mezzanine package and paste it in an app where you want to use it, then edit that copied files. This is written in documentation for mezzanine, I missed that part.

How to set multiple settings.py for sites framework django?

Am trying to set up multiple website with same base. While browsing, came to know Django has Sites framework which I could use.
I didnt get how to set multiple settings.py file with site id. Any ideas anyone?
Thanks in advance :)
To serve multiple sites from the same Django instance you do not need multilple settings.py files.
A simple method is to omit the SITE_ID setting from the Sites framework. Then include the Sites framework middleware:
'django.contrib.sites.middleware.CurrentSiteMiddleware'
This automatically passes a request object to Site.objects.get_current() on every request. It also allows your Django application to detect the current site via request.site.
You would need to make sure to setup multilple virtual hosts using your NGINX or apache instance to route traffic from each site to your server.
you can have multiple setting file for example develop.py and production.py
steps:
create a settings folder inside the project
Add all of the settings file to that folder
while running server
./manage.py runserver -- settings=project_name.settings.required_settingfile
for example:
./manage.py runserver --settings=myproject.settings.develop

How do I implement django-articles app into a new project via pip?

I'm trying to install the following django app from the cheeseshop:
https://bitbucket.org/codekoala/django-articles/overview
This is my first day of Django-ing and I'm unsure what to do to get the app's folder populated inside my project.
So far, I've pip installed the app into my virtualenv. This is verified by opening a python shell and getting no errors when I run "import articles"
I've edited the settings.py file and added it to the list of installed apps. I believe this to be OK as I can then run runserver without any "module not found" errors.
syncdb also ran fine.
Where do I go from here?
ie, I would like to have a section of the website called News which uses this app. I have no routes or other apps configured yet, just a clean Django with psycopg2.
EDIT: Enabling the default admin site, I can manage the Articles there, but still unsure of how these will be displayed on the site when I have no app folder created for them. When trying to startapp articles, I'm warned it's conflicting name with an existing module..
No need to create a new app called articles. As you are able to import articles via the python console you have successfully installed it. You can find it in your virtualenv folder in the folder site-packages:
/path_to_your_virtualenv/.virtualenvs/<virtualenvname>/lib/<pythonversion>/site-packages
You can use this app, installed via pip, as it is an app which lives in your project folder.
You just need to include the articles urls in your own urls.py. Since you say you want it under News, this would do fine:
urlpatterns = patterns('',
(r'^news/', include('articles.urls'),
)
Note though that the readme for the articles app implies that you'll need to create your own base template for it to inherit from. Just create a base.html file in a directory called templates under your project, give it a basic HTML structure, and put in {% block content %}{% endblock %} in the relevant place (and the same for the other blocks mentioned in the readme).
You should probably do the Django tutorial anyway, to understand exactly what's going on with the URL and the templates.

templatetags imported in runserver but not on wsgi

im using django 1.2 and I am trying to deploy django using apache mod_wsgi.
My app works fine using the development server, but when I try to use the wsgi, it can not load file containing template filters.
I have it in structure like /app/subapp/templatetags/core_filters.py, init.py is located where it is supposed to. When I try to open any view loading the code, or template loading {% load core_filters %} exception occurs. It says it is not a valid tag library, at lists all the apps it tried to find core_filters in, but my app.core.templatetags.core_filters is not among them although it is listed in installed apps.
Any suggestions, sollutions?
Any chance you accidentally left your local_settings.py file on the live server, causing some pathing issues or there's some other difference between your settings.py and local_settings.py files?
There was an error on the python path. uWsgi had different python path that contained another package with the same name

Appropriate placement for my testcases belonging to a non-app in Django

I have built my website in Django. And like any other django project I have got apps inside the project root directory and some special folders like(extensions a.k.a custom django command extensions). With an app, we dont have any problem with having testcases. "tests.py" inside the app directory will be the solution. But for a special folder(which is not an app or which doesn't have a models.py) where do I place the testcases. I tried placing the tests.py inside the extensions directory and it said the directory is not a model and unable to run the tests. HOw do I solve this? How can I have a proper placement of testcases related to non-apps?
I think it will work to put them in a tests/ directory at the project level.
If, for some reason, it doesn't then try creating an empty models.py in your extensions directory.