Forums

Changing Mezzanine theme and homepage

Can someone explain more in depth how to do change the homepage and the theme as I don't fully understand the explanations I could find: "copy the relevant HTML, CSS and JavaScript files into it from Mezzanine that you wish to modify, and then add the theme app’s name to your project’s INSTALLED_APPS setting. Be sure to add the theme to the top of the INSTALLED_APPS list, so that its templates are found before Mezzanine’s versions of the templates."

"HOMEPAGE AS AN EDITABLE PAGE IN THE PAGE TREE This pattern gives us a normal Page object, so that your homepage can be managed via the page tree in the admin. If you use this pattern, you'll need to create a page in the page tree, and specify its URL (in the Meta Data section) as "/", which is the value used below in the {"slug": "/"} part. Also note that the normal rule of adding a custom template per page with the template name using the page's slug doesn't apply here, since we can't have a template called "/.html" - so for this case, the template "pages/index.html" should be used if you want to customize the homepage's template."

Hm, I don't suppose there are any mezzanine experts out there watching the forums? You might get better help on the mezzanine mailing list, or on their IRC.

Still, we could have a crack at it. From what I understand from this guide the way it works is that mezzanine has some default templates, but you can override them by using templates with the same names in an app you create.

so you start by doing

python manage.py collecttemplates

inside your project folder. that gathers up all the mezzanine templates from where they're hidden in the virtualenv into a folder called templates:

tree templates

at this point you could go in and just hack any one of those templates individually. but what the mezzanine developers suggest (which is slightly more complicated, but a good idea if you ever want to upgrade mezzanine), is that you create an "app" to store your templates in

python manage.py startapp mytemplates

you need to add that app to your INSTALLED_APPS in settings.py, and make sure to put it at the top of the list:

INSTALLED_APPS = (                                                                                                                                      
     "mytemplates",                                                                                                                                      
     "django.contrib.admin",                                                                                                                             
     "django.contrib.auth",  
[...]

This means that any templates in mytemplates that have the same name as the mezzanine default ones will override them.

  • You need to Reload Web App for this change to take effect.

So you can try one like this:

mkdir mytemplates/templates
cp templates/base.html mytemplates/templates/base.html

Then edit base.html. I put a big <h1>HELLO WORLD</h1> just after the <body> tag just to see if it works.

To activate your changes, do a

python manage.py collecttemplates

and now you'll find the base.html inside the templates directory is the same as the one in mytemplates/templates. go visit your site, and you should see the big hello world!

hope that helps!

oops, sorry, that post was half-finished, i'll re-edit it...

re making the homepage editable, it sounds like that's something best attempted once you've got a bit more comfortable with playing with other editable pages, with urls.py, and you understand what a Page object is (I don't!)

I think it's easiest if I note each of my steps: I currently have a mezzanine project called cardiffstudentsproject (within a virtualenv called cardiffstudents) which I have set up with a MySql database. After trying to run the code: python manage.py collecttemplates, it gives an error "ValueError: u'django.contrib.admin' is not in list"?

Not sure what I did but the code now executed: "Copied 45 templates". And after doing "tree templates" at the end it gives "10 directories, 44 files" which matches what I have seen on another guide.

Quick question about something which I keep seeing when code is executing, what is this about "warn("You haven't defined the ALLOWED_HOSTS settings, which " From reading is that just meaning that I can set what domains my website is allowed to run on e.g. for now it would just be http://TeamJJSL.pythonanywhere.com/ if I put that address into the ALLOWED_HOST setting?

Back to the themes, I started an app called "themeapp" and added it to my installed apps in settings.py. After doing: mkdir themeapp/templates cp templates/base.html themeapp/base.html

when I try to execute python manage.py collecttemplates I get the same error as I did in the last post, "ValueError: u'django.contrib.admin' is not in list", this error seems to occur whenever I have my new app in the INSTALLED_APPS part of settings.py.

Thanks again and sorry for so much content I'm asking about, there isn't much help for mezzanine let alone for it being ever so slightly different on pythonanywhere compared to the odd few half guides there are.

Glad to hear there's progress!

re: the ALLOWED_HOSTS warning, it's ok to ignore that for now. when you're ready to put your app into "production", ie when you want people to start using it for real, you'll want to switch the DEBUG setting to False, and then put the hostname into ALLOWED_HOSTS, both in settings.py.

re: your attempt to override a template, that's totally my fault, I'm sorry, i made a mistake in my instructions. you have to put the templates inside the "templates" folder, inside the app, so the correct command should be:

cp templates/base.html themeapp/templates/base.html

i'll fix my post above so that other people don't trip up.

cardiff students eh? do I sense the bad influence of Daniele and the DjangoWeekend?

Thanks, when trying to do collecttemplates I get the same error message as before, it seems it won't let me run collecttemplates when themeapp is at the top of my list of INSTALLED_APPS again, so I don't know if I need to move where themeapp is in the list of installed apps or what as django.contrib.admin.is in the list but doesn't work when themeapp is being called first. Not sure why it doesn't work, any ideas?

When I run collecttemplates with themeapp not on the list of installed apps it runs just overwrites the files that are already in my main projects template folder

Could I take a look at your code, ideally while you have themeapp added to the INSTALLED_APPS list? That would help me work out what's going on.

(cardiffstudents)22:37 ~/cardiffstudentsproject $ python manage.py collecttemplates
/home/TeamJJSL/.virtualenvs/cardiffstudents/local/lib/python2.7/site-packages/mezzanine/utils/conf.py:51: UserWarning: You haven't defined the ALLOWED_HOSTS settings, which Django 1.5 requires. Will fall back to the domains configured a s sites. warn("You haven't defined the ALLOWED_HOSTS settings, which " Traceback (most recent call last): File "manage.py", line 10, in <module> from settings import PROJECT_ROOT, PROJECT_DIRNAME File "/home/TeamJJSL/cardiffstudentsproject/settings.py", line 368, in <module> set_dynamic_settings(globals()) File "/home/TeamJJSL/.virtualenvs/cardiffstudents/local/lib/python2.7/site-packages/mezzanine/utils/conf.py", line 154, in set_dynamic_settings move("INSTALLED_APPS", "django.contrib.admin", len(s["INSTALLED_APPS"])) File "/home/TeamJJSL/.virtualenvs/cardiffstudents/local/lib/python2.7/site-packages/mezzanine/utils/conf.py", line 39, in <lambda> move = lambda n, k, i: s[n].insert(i, s[n].pop(s[n].index(k))) ValueError: u'django.contrib.admin' is not in list (cardiffstudents)21:12 ~/cardiffstudentsproject $

(cardiffstudents)22:37 ~/cardiffstudentsproject $ python manage.py collecttemplates

/home/TeamJJSL/.virtualenvs/cardiffstudents/local/lib/python2.7/site-packages/mezzanine/utils/conf.py:51: UserWarning: You haven't defined the ALLOWED_HOSTS settings, which Django 1.5 requires. Will fall back to the domains configured a s sites. warn("You haven't defined the ALLOWED_HOSTS settings, which "

Traceback (most recent call last): File "manage.py", line 10, in <module> from settings import PROJECT_ROOT, PROJECT_DIRNAME File "/home/TeamJJSL/cardiffstudentsproject/settings.py", line 368, in <module> set_dynamic_settings(globals()) File "/home/TeamJJSL/.virtualenvs/cardiffstudents/local/lib/python2.7/site-packages/mezzanine/utils/conf.py", line 154, in set_dynamic_settings move("INSTALLED_APPS", "django.contrib.admin", len(s["INSTALLED_APPS"])) File "/home/TeamJJSL/.virtualenvs/cardiffstudents/local/lib/python2.7/site-packages/mezzanine/utils/conf.py", line 39, in <lambda> move = lambda n, k, i: s[n].insert(i, s[n].pop(s[n].index(k)))

ValueError: u'django.contrib.admin' is not in list

(cardiffstudents)21:12 ~/cardiffstudentsproject $

Didn't mean to post twice, it's the same code though from the bash console when trying to execute the collecttemplates command, also when themeapp is in my installed apps my website just comes up with an unhandled exception error

Feel so stupid haha, I missed out a comma on installed apps, now collecttemplates runs, however collecttemplates just tries to overwrite all the templates in my actual projects folder, should it be creating copies of the templates in my newapps template folder? e.g. should I cd themeapp then run collecttemplates? Or can I now just place a .css file with the new theme e.g. one from here http://bootswatch.com/ somewhere and then just change the path in base.html for the project?

Maybe have another read of this post from further up? Basically collecttemplates will pull together all the "normal" mezzanine templates, but it also pulls in all the templates from your apps, and it will overwrite the mezzanine ones with the ones from your app if you have the same name, and it puts them into the project templates folder.

so you should work on the templates in your themeapp/templates folder, and when you are ready to "publish" them, you use collectemplate, which will copy them into the main project templates folder.

ps take a look at the markdown guide that's linked at the bottom of the post editing box. indent code blocks / console output listings by 4 spaces, then they'll be nicely styled in your posts. you can edit old posts.

Wheres is this guide linked? and what is markdown I remember seeing something about it before?

I seem to have followed every single step of every single guide I can find and nothing is working, I don't understand why it will not work. I have a new app called themeapp which has directory templates/ which has a duplicate base.html and index.html and another directory templates/includes/ which has a duplicate footer_scripts.html file, the other directory it has is static/css/ which has a file bootstrap-theme-cosmo.css which is a css file from http://bootswatch.com/cosmo/bootstrap.css and the file codehilite.css which I got from running "python manage.py pygments_styles colorful >themeapp/static/css/codehilite.css". In settings.py for my actual project I have added "themeapp", and "mezzanine_pagedown", to my installed apps list. In base.html in both copies I have added <link rel="stylesheet" href="{% static "css/codehilite.css" %}"> and <link rel="stylesheet" href="{% static "css/bootstrap-theme-cosmo.css" %}"> after the 3 other lines which link to css/bootstrap.css, css/mezzanine.css, css/bootstrap-theme.css. I installed Pygments using "pip install mezzanine-pagedown Pygments" and added the necessary stuff to settings.py and urls.py which you can see in this guide http://rodmtech.net/docs/mezzanine/a-mezzanine-tutorial-take-2/#part-1-install-through-pagedown-setup, I've also tried other two other guides http://rosslaird.com/blog/customizing-mezzanine/ and http://bitofpixels.com/blog/mezzatheming-creating-mezzanine-themes-part-1-basehtml/. Any ideas at all why on earth nothing will work?

the markdown guide is underneath the textbox you use to enter a new post. just to the left of the "Add post" button.

turning to your questions; can you expand at all on "nothing will work"? what's a specific example of a thing, which you think should work, which isn't working?

Changing the theme, homepage, changing the pages so that they don't have those navigation bars on the bottom and left hand side, getting rid of the twitter feed on the page, that's most of what I've tried so far. Think I might just start over and make a website without mezzanine as I'm running out of time and I think I have a decent understanding of django now anyways, so don't worry about this post anymore, but thanks anyway, this post has been helpful for django in general.

You'll get there if you persist with it. It sounds like you're trying to do too many things at once. Start with one small thing, and see if you can get that working. Be clear on how and why it works.

I would move your current themeapp to one side, and start again with a new, totally empty one. just start with one template, base.html, and try and make one small change to that. just change the header text, or the window title. something small. if that's working, then you know how to customise your base template, and that will always work. great.

save you work into a version control system like git, so you can save your progress, and it's always easy to go back to a working state.

next you might try and make changes to CSS. see the new css file load if you visit its url directly, see it change the styling of your page, ok, good, you've figured out how that works, save your progress again.

then make your changes one by one. maybe your next objective is to try removing the menu bar, and it's work on a different template, or maybe it involves multiple templates, and if you're having a particular problem with that, then it'll be easier to come back here and ask a specific question.

next you might try and install a new package, like pygments. if you run into problems with that, again, we can help you debug, maybe it's an issue with getting it installed into the right virtualenv, or putting the right entry into settings.py, or whatever.

so, if you have time, we're still happy to help. if you can ask specific questions, and tackle problems one at a time, and be clear about what you're trying to achieve and what's not working...

Okay thanks, yeah I'll see how much time I have as I need to have my project done in a couple of weeks along side my other university work haha so just want to rattle out a decent website where I can shove some information and pictures which looks okay now, thanks for being so helpful! Might have to come back to mezzanine and proper web development over the summer

Tree templates command returns ... -bash: tree: command not found

If I try

python manage.py collecttemplates tree templates

Then I get

usage: manage.py collecttemplates [-h] [--version] [-v {0,1,2,3}]
                                  [--settings SETTINGS]
                                  [--pythonpath PYTHONPATH] [--traceback]
                                  [--no-color] [--noinput] [-t TEMPLATE] [-a]
manage.py collecttemplates: error: unrecognized arguments: tree templates

What is tree templates supposed to do ?

[edit by admin: formatting]

The command

tree templates

...should be run on a command line on its own; it displays the directory hierarchy underneath the directory templates in an ASCII-art fashion. tree is installed on PythonAnywhere by default -- were you running the command on PythonAnywhere when you got the "command not found" error?