Posts

Showing posts with the label redirect

Redirect with get_context_data in generic detailview django

Redirect with get_context_data in generic detailview django I have this view where i needed two models Book and UserFav so I used context for that: class BookDetailView(LoginRequiredMixin, generic.DetailView): model = Book template_name = 'book_detail.html' def get_context_data(self, **kwargs): context = super(BookDetailView, self).get_context_data(**kwargs) context.update({ 'fav_list': UserFav.objects.filter(user=self.request.user) }) return context and another view function def favorite(request, pk): book = get_object_or_404(Book, pk=pk) fav, created = UserFav.objects.get_or_create(user=request.user) fav.favorites.add(book) return render(request, 'book_detail.html', {'book': book}) form for the favourite function <form action="{% url 'favorite' book.id %}" method="post" style="display: inline;"> {% csrf_token %} <button type="subm...

JS: Forward to a site with random parts in the URL

JS: Forward to a site with random parts in the URL by opening a HTML-site, I want to redirect to the following page: www.xyz.de?user=default&f1= OPTION1 &f2= OPTION2 &f3= OPTION3 &f4= OPTION4 &f5= OPTION5 &... etc. The value for the "OPTIONS" should be randomly selected from a list (array) for every OPTION (1,2,3,4,5,..). How can I do this with Javascript? kind regards is the problem to redirect or to generate the string? – Nina Scholz Jun 30 at 18:25 1 Answer 1 Hopefully this will help you, you didn't provide much details or a demo code, so this is from my point of understanding only. <p id="Link">Link Here</p> <p id="randoms">Randomly Sortde Array</p> <script> var o...

HAProxy and reqrep path rewriting with redirect configuration

HAProxy and reqrep path rewriting with redirect configuration With HA Proxy 1.5 I need to rewrite URL from http://main.domain.com/my-foo to http://othersite.com:8081/other-bar http://main.domain.com/my-foo http://othersite.com:8081/other-bar Here is what I tried: frontend ft_def bind :80 mode http acl has_special_uri path_beg /my-foo use_backend def if has_special_uri default_backend def backend def mode http option forwardfor reqirep ^([^ ]* )/my-foo(.*) 1/other-bar2 server myserver othersite.com:8081 This works: URL http://main.domain.com/my-foo/home.html becomes http://othersite.com:8081/other-bar/home.html http://main.domain.com/my-foo/home.html http://othersite.com:8081/other-bar/home.html and in the browser the initial URL http://main.domain.com/my-foo/home.html appears. http://main.domain.com/my-foo/home.html I...