I am developing a django-application on the top of pinax. I want to modify the side menu which appears after the user is logged in and has options 'account', 'password settings' and 'delete account'. I want to add more options according to my application. I just can't seem to find its templates. I have searched everywhere in my project folder. I know it is downloaded because I have all those functions available but WHERE ARE THE FILES? Any suggestions?
Presuming you mean the sidebar seen in the account/settings/ url, then you'll need to modify the original file, or clone a copy of it in your project and override it from there.
The name of the file is "base.html".
Here's a snippet of code from mine:
{% block subnav %}
<nav class="settings-nav">
<div class="heading">Settings</div>
<a class="account-settings" href="{% url "account_settings" %}">
{% trans "Account" %}
</a>
<a class="account-password" href="{% url "account_password" %}">
{% trans "Change password" %}
</a>
<a class="account-delete" href="{% url "account_delete" %}">
{% trans "Delete account" %}
</a>
As for where you find it, there's a few different places to look, depending on how you installed pinax.
1) Outside of a virtual environment, you'll find it at /lib/python3.6/site-packages/pinax/templates/templates/account/base.html
2) Inside of a virtual environment (like using pipenv), you'll have to find it from within the /home/myuser/.local/share/virtualenvs/... subtree.
Issue a find /home/myuser -name base.html to locate the file with the same subtree as found in the first step.
One thing I will mention is that you should not modify that specific file, only template it into your project and override it. In this way, if your code ever moves to another machine your changes will be lost.
Copy that base.html file to myproject/templates/account/base.html and modify it there.
Hope that helps!
Related
All of my user's have the option to link a profile picture. There are several templates that need to load this profile picture. If the user has not uploaded a picture, we use a default. When I want to display this profile picture, my code looks like this
<img src="{% if user.profile_picture.search_thumbnail.url %}{{ user.profile_picture.search_thumbnail.url }}{% else %}{% static "alternate.jpg" %}{% endif %}">
This is way too verbose for me, especially considering I need to repeat it out in multiple templates. I could use {% with %} blocks to store user.profile_picture.search_thumbnail.url, but that won't help me too much.
My solution was to write a function attached to the user model that returns the url of the static file. Unfortunately, the {% static %} is a template function. {% url %} has an equivalent function on the server called django.core.urlresolvers.reverse(). Does the alternative thing exist for the {% static %} tag?
In case anyone asks, I want to use the static function because my static files are stored in different places depending on the environment. My dev machine serves files locally, while my PRD machine serves static files from s3.
Thank you,
Nick
why not write a filter so you can do this.
<img src="{{ user.profile_picture.search_thumbnail.url|custom_filter }}">
and in the custom_filter you read from the settings.STATIC_URL to return the correct URL the user one is not set.
you could make the filter even shorter like this
<img src="{{ user|user_pic_url }}">
and in the filter pull out the .profile_picture.search_thumbnail.url /checks
This is what the static templatetag does underneath, and you can use it just fine in your own code:
from django.contrib.staticfiles.storage import staticfiles_storage
def static(path):
return staticfiles_storage.url(path)
I have three SurveyWizardViews all of which use the same standard wizard_form.html which is located at templates/formtools/wizard/wizard_form.html as per the documentation
I have added some basic logic to this template which is designed to detect which page of the form the user is on so that I can include a non standard page/step, this is an image with a JS slider bar underneath. This all works perfectly.
{% if wizard.steps.current == '6' %}
<img src="{% static "survey/images/pathtwo/" %}{{display_image}}"/>
<section>
<span class="tooltip"></span>
<div id="slider"></div>
<span class="volume"></span>
</section>
{% endif %}
However I now want to have a slightly different experience for the user depending on which View/URL they are coming from.
Question Is it possible to detect which URL the view is currently using to look at the page? e.g.
{% if URL.current == 'www.mywebsite.com/experiment/surveyone/' %}
do X
{% if URL.current == 'www.mywebsite.com/experiment/surveytwo/' %}
do y
I have done some searching but Im not even sure what I'm searching for to be honest. Any help would be much appreciated.
You can use the request context variable. Something like:
{% if 'experiment/surveyone' in request.path %}
do this
{% endif %}
I prefer using in instead of == to ignore trailing and leading slashes. If you want the whole thing try the build_absolute_uri method. Also check what options does request offer to you (https://docs.djangoproject.com/en/dev/ref/request-response/#httprequest-objects).
Finally, don't forget to add django.core.context_processors.request to your TEMPLATE_CONTEXT_PROCESSORS (I think it is added by default).
I tried to find the solution to this problem on stackoverflow and google but couldn't find it. The issue is using same controller twice on the same page and only the first controller mention gets invoked.
So I have a base template and main page. Now mainpage inherits two completely different blocks - sidebar block and main content block. both needs my controller - myController but the moment I use ngController with same controller name on the page twice on these two completely different divs only the first one gets executed.
Gist: https://gist.github.com/keshavagrawal89/356bb68068ac3ed4ae4e#file-samecontroller
<!-- base.html -->
<div>{% block sidebar %}{% endblock %}</div>
<div>{% block content %}{% endblock %}</div>
<!-- MainPage.html -->
{% block sidebar %}
<ul ng-app="myApp" ng-controller="myController">
<li></li>
</ul>
{% endblock %}
{% block content %}
<div ng-app="myApp" ng-controller="myController"> my page content</div>
{% endblock %}
What am I missing?
You cannot use multiple ng-apps in the same application. Ideally you would just put it in the root of your app or create an app including multiple apps and place it in the root, in the example below all the entities registered in both the apps will be loaded into the myApp module.
ex:-
angular.module('myApp', ['App1', 'App2']);
But in your case it seems like your app may or may not be the same, so best way would be to manually bootstrap your app.
But remember when manually bootstrap your app it is generally not to use ng-app
angular.element().ready(function() {
angular.bootstrap(elmRoot, ['myApp']);
});
Plnkr
Note: You should not use the ng-app directive when manually bootstrapping your app.
the only problem with your code is multiple ng-app's as PSL says on the comment.
ng-app declares the scope for DOM objects for angularjs to parse and it should be use once
typically in the html tag like
<html ng-app="app"> or <html ng-app>
i recommed using a name for the app module
here is a working example
I have set up Octopress with my Github account at http://acgrama.github.io/. The main page is a vanilla HTML, non-Octopress landing page, and the blog is set up in Octopress under source/blog.
(I have followed the instructions in the "Landing Page vs. Blog Index" section of http://octopress.org/docs/theme/template/)
Everything is ok, except when I go to http://acgrama.github.io/blog/ I see a link to the blog archives instead of the latest blog posts.
Some symptoms that I noticed: when I do rake generate, I get the following output:
## Generating Site with Jekyll
identical source/stylesheets/screen.css
Configuration file: /home/***/octopress/_config.yml
Source: source
Destination: public
Generating...
Pagination: Pagination is enabled, but I couldn't find an index.html page to use as the pagination template. Skipping pagination.
done.
Looking under source/blog/index.html, I understand that the posts in paginator.posts are iterated and shown (?), after which the Older/Newer and Blog Archives links are shown:
<div class="blog-index">
{% assign index = true %}
{% for post in paginator.posts %}
{% assign content = post.content %}
<article>
{% include article.html %}
</article>
{% endfor %}
<div class="pagination">
{% if paginator.next_page %}
<a class="prev" href="{{paginator.next_page_path}}">← Older</a>
{% endif %}
Blog Archives
{% if paginator.previous_page %}
<a class="next" href="{{paginator.previous_page_path}}">Newer →</a>
{% endif %}
</div>
</div>
These made me think that paginator.posts is empty for some reason, hence nothing happens in the first for loop and this is how only the Blog Archive link ends up being shown.
Am I doing anything wrong? Can this issue be solved at all?
I had the exact same issue and I found an answer based on your suspicion that paginator.posts was empty.
Update _config.yml and set the following:
paginate_path: "posts/:num"
to
paginate_path: "blog/posts/:num"
After that and a rake generate and rake preview, the /blog page showed my posts
This would lead me to believe that the paginator must be made aware of the subdirectory change for /blog. Really seems like something that should be in the docs
Is there any functionality in admin site that allow to implement for every add/change form cancel button, that redirects me to list of that form objects. I mean some general solution for any form.
Add admin/submit_line.html in your project's templates directory. Use the code from the default submit_line.html, and add your cancel button. You can link it to just "../" to make it always just go up one level. Then do any necessary CSS styling to make it look right.
Create a file: yourapp/templates/admin/submit_line.html
I use Bootstrap, but you can change this easily
{% extends "admin/submit_line.html" %}
{% block submit-row %}
{{ block.super }}
Cancel
{% endblock %}
Be sure that your application is above "admin" in INSTALLED_APPS.
Looks like this in German locale:
<input type="button" name="Cancel" value="Cancel">
You can this line anywhere inside admin/submit_line.html