django-templates

Remove form from DOM using JavaScript

怎甘沉沦 提交于 2019-12-12 06:38:58
问题 I have three radio buttons.. each radio buttons on click have an independent form that appears. I need to remove form from DOM when i click on a radio button. and there are a third one not ready yet. When i click on the first radio button only its form appears, the other two are removed from DOM. Same for other. I don't have a good idea about JavaScript. Html: <div class="page-header"> <h1>Backtesting{% if form.instance.pk %}: {{form.instance.title}} {% endif %}</h1> </div> <div class="row">

Django redirect URL to latest created blog post

只谈情不闲聊 提交于 2019-12-12 06:38:07
问题 I want to have a redirect in my urls.py so that the latest Post entry in my Blog application is automatically loaded when people visit the Blog application index domain. A Blog.Post detail is supplied via the blog.views.post_detail(request, slug) method and a blog post will end up with the URL: www.example.com/blog/this-is-the-slug/ When someone loads the www.example.com/blog domain I want them to be automagically redirected to the latest blog post individual entry. I'm very new to the urls

Django CSS Attachment

五迷三道 提交于 2019-12-12 06:11:59
问题 I have gotten it to now work locally thanks to @Selcuk by adding to the bottom of the settings.py STATICFILES_FINDERS & STATICFILES_DIRS . The page works on with stylesheet locally BUT once I push to my heroku web app it fails to run the stylesheet. Code for Base Template <!DOCTYPE html> <html> <head> <title>ToolShare » Mohammad Daraghmeh</title> <!-- Fav Icon --> <link rel="shortcut icon" href="http://bit.ly/1xDbduz" type="image/x-icon"> <link rel="icon" href="http://bit.ly/1xDbduz" type=

Passing additional data to a template in Django

浪尽此生 提交于 2019-12-12 05:28:10
问题 Every time I code something using Django, I am faced to the same issue (I think this is due to my lack of experience using this framework): I know how to pass arguments I had from a queryset to a template and how to display it but I don't know how to add argument computed in the view and use them in the template. Simple View (I master it) : Example: Retrieve a list of Pizzas and display them in a template views.py Pizzas = Pizza.objects.all() return render_to_response( "pizza.html" , {'pizzas

Image Not displaying in django getting 404 error

ⅰ亾dé卋堺 提交于 2019-12-12 05:07:24
问题 I followed official django documentation for image field.I am able to store the image in the database but when I try to display it in browser I am getting 404 error. My settings file, TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR,"templates")], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth

Django 'str' object has no attribute 'as_widget'

拈花ヽ惹草 提交于 2019-12-12 04:58:32
问题 I've made a register form in django and i've created a template tag add_class to create users, the problem is i'm getting this error: 'str' object has no attribute 'as_widget' to {{ form.username|add_class:'form-control' }} register_user.html <form class="form-horizontal" method="POST" action=""> {% csrf_token %} {% if form.errors %} <p>Your username and password didn't match. Please try again.</p> {% endif %} <div class="form-group"> <div class="col-md-12"> {{ form.username|add_class:'form

django admin custom template page not found error

馋奶兔 提交于 2019-12-12 04:56:21
问题 I am trying to modify the django admin interface and I cannot see the custom templates. In the admin.py file I added this model admin class FTPAdmin(admin.ModelAdmin): def get_urls(self): urls = super(FTPAdmin,self).get_urls() my_urls = patterns('', (r'^ftp/$',self.admin_site.admin_view(self.FTPView))) return my_urls + urls def FTPView(self, request): form = FTPForm() if request.method == 'POST': if form.is_valid(): return HttpResponseRedirect('/admin/') return render_to_response(request,

excel in django

旧时模样 提交于 2019-12-12 04:47:05
问题 How can i make user to downlaoad a excel from the django app.i HAVE A MODEL WHICH gives the report.Now i want a option from user can download the file in excel form.ANy Solution 回答1: You can output the data as .csv which is easily imported into MS Excel. http://docs.djangoproject.com/en/dev/howto/outputting-csv/ EDIT After I wrote that I got curious if there actually was some way to do it directly to excel format and found: http://www.python-excel.org/ That made me wonder why you didn't

Setting specific day to print specific message in the django template

泪湿孤枕 提交于 2019-12-12 04:30:58
问题 Here is my model: class Sitting(models.Model): sit_date = models.DateField(blank=False) cut_off_date = models.DateField(null=True, blank=True) ballot_date = models.DateField(null=True, blank=True) sess_no = models.ForeignKey(Session, on_delete=models.CASCADE) genre = TreeForeignKey('Genre', null=True, blank=True, db_index=True) here is my view: def sitting_list(request): sitting=Sitting.objects.select_related('genre') return render( request, 'genre/sitting_list.html', {'sittings':sitting, },

how to serve Result file using Django?

让人想犯罪 __ 提交于 2019-12-12 04:01:15
问题 I have developed an App that takes input file from the upload method without using model and run some code behind the server like this: /MyDjango_project_directory/media/input.csv And generates some result files in a location like this. /Virtualenv_directory/MyDjango_project_directory/OutPut_files_directory/result.csv /Virtualenv_directory/MyDjango_project_directory/OutPut_files_directory/result.png Presently I am just moving the output files into "media" folder through "sys" command in