forms.py
?
manage.py migrate
gives me an error that there is no such table
forms.py
file
class UserPostList(generics.ListAPIView):
model = Post
serializer_class = PostSerializer
logging.debug("hello")
def get_queryset(self):
queryset = super(UserPostList, self).get_queryset()
return queryset.filter(author__username=self.kwargs.get('username'))
somebody can help me how to add class active
for html templates, eg: nav menus, bassed in generic.ListView
?
some idea i was try with {% if request.resolver_match.url_name == "name" %}
and {% if request.get_full_path == '/mypage/' %}
but it isn't work.. i think may it because pagination
in generic.ListView
...
any idea how to solved it?
@agusmakmun how about using templatetags?, for example:
assuming your url like this:
url(r'^direktorat/$', DirektoratListView.as_view(), name="direktorat-list"),
templatetags
from django import template
register = template.Library()
@register.simple_tag
def active(request, pattern):
import re
if re.search(pattern, request.path):
return "active"
return ""
then you can use it at template like this:
{% load active %} # load the templatetags
{% url 'direktorat-list' as direktorat_list_url %} #save it as variable for future change
<!-- link -->
<li class="{% active request direktorat_list_url %}"><a href="{{ direktorat_list_url }}">Direktorat</a></li>
@pace-noge woow... that was awesome, i never think it with templatetags before..
{% load nav_menus_active_tags %}{% url 'direktorat-list' as direktorat_list_url %}
<li class="{% if request.resolver_match.url_name == "popular_videos_page" %}{% active request direktorat_list_url %}{% endif %}">
thank you so much.. :smile:
{% load nav_menus_active_tags %}
{% url 'popular_videos_page' as popular_videos_page %}
<li class="{% if request.resolver_match.url_name == "popular_videos_page" %}{% active request popular_videos_page %}{% endif %}">
<a class="nav-popular" href="{% url 'popular_videos_page' %}">Popular</a>
</li>
@pace-noge but, are it possible with multiple path?
egg: html li
have some childs like a dropdown. if one of child selected then li
will add to class active
.
egg:
<li><a href="#">Settings</a>
<ul>
<li><a href="#">Profile</a></li>
<li><a href="#">Change Password</a></li>
</ul>
</li>
0
down vote
favorite
i want to create django project with two templates main list and details from the main list using genetic views List view and details views. the main list work but not work details list. this my code can somebody to help me ?
urls.py
urlpatterns = [
url(r'^$', ListView.as_view(
model = Test,
queryset = Test.objects.all(),
context_object_name = "test_list",
template_name='blog\test_list.html')),
url((r'^(?P<pk>\d+)-(?P<slug>[-\w]+)/$', DetailView.as_view(
context_object_name="test_list1",
model=Test,
template_name='blog\Test_details.html'
), name="test"),
]
html code test_list
{% for test in test_list %}
<h2> <a href="{{test.id}}">{{test.Title}}</a></h2>
{% endfor %}
html code test_details
<h2>{{ test.Title }}</h2>
.......................
Hi all!
I am making web app, when user sees web page for the first time, going to create User
for him/her with some random name/pwd and set it in SESSION, everytime user loads page, it feels like he already registered, whenever user wants to sign up, I will offer REST API to change his/her username/pwd then reload this session, do you think this is good solution or are there any other way doing this?
P.S. Asked in DjangoGirls/tutorial also
P.S. Sorry for my broken English, I am not a native speaker and can create some ambiguous sentences