Question

In: Computer Science

please write Django web app with simple html page, that you can upload the image and...

please write Django web app with simple html page, that you can upload the image and display image and display path of the image on the PC.

Solutions

Expert Solution

The very first step is to add below code in the settings.py file.

   MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
   MEDIA_URL = '/media/'


MEDIA_ROOT is for server path to store files in the computer.
MEDIA_URL is the reference URL for browser to access the files over Http.

In the urls.py we should edit the configuration like this
   if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)


A sample models.py should be like this, in that we have created a Hotel model which consists of hotel name and its image.
In this project we are taking the hotel name and its image from the user for hotel booking website.

   # models.py
   class Hotel(models.Model):
   name = models.CharField(max_length=50)
   hotel_Main_Img = models.ImageField(upload_to='images/')

Here upload_to will specify, to which directory the images should reside, by default django creates the directory under media directory which will be automatically created when we upload an image. No need of explicit creation of media directory.

We have to create a forms.py file under image_app, here we are dealing with model form to make content easier to understand

   # forms.py
   from django import forms
   from .models import *
  
   class HotelForm(forms.ModelForm):
  
   class Meta:
   model = Hotel
   fields = ['name', 'hotel_Main_Img']

Django will implicitly handle the form verification’s with out declaring explicitly in the script, and it will create the analogous form fields in the page according to model fields we specified in the models.py file.

Now create a templates directory under image_app in that we have to create a html file for uploading the images. HTML file should look like this.


   <!DOCTYPE html>
   <html lang="en">
   <head>
   <meta charset="UTF-8">
   <title>Hotel_image</title>
   </head>
   <body>
   <form method = "post" enctype="multipart/form-data">
   {% csrf_token %}
   {{ form.as_p }}
   <button type="submit">Upload</button>
   </form>
   </body>
   </html>


Related Solutions

Using the combination of HTML and PHP, implement a web page where the users can upload...
Using the combination of HTML and PHP, implement a web page where the users can upload a text file, exclusively in .txt format, which contains a string of 1000 numbers, such as: 71636269561882670428252483600823257530420752963450 85861560789112949495459501737958331952853208805511 65727333001053367881220235421809751254540594752243 52584907711670556013604839586446706324415722155397 53697817977846174064955149290862569321978468622482 83972241375657056057490261407972968652414535100474 82166370484403199890008895243450658541227588666881 96983520312774506326239578318016984801869478851843 12540698747158523863050715693290963295227443043557 66896648950445244523161731856403098711121722383113 05886116467109405077541002256983155200055935729725 16427171479924442928230863465674813919123162824586 17866458359124566529476545682848912883142607690042 24219022671055626321111109370544217506941658960408 07198403850962455444362981230987879927244284909188 84580156166097919133875499200524063689912560717606 62229893423380308135336276614282806444486645238749 73167176531330624919225119674426574742355349194934 30358907296290491560440772390713810515859307960866 70172427121883998797908792274921901699720888093776 Your code should contain a PHP function that, accepting the string of 1000 numbers in input, is able to: 1) Find the 5 adjacent numbers that multiplied together...
Using a combination of HTML/PHP, implement a web page where the users can upload a text...
Using a combination of HTML/PHP, implement a web page where the users can upload a text file, exclusively in .txt format, which contains a string of 400 numbers, such as: 71636269561882670428 85861560789112949495 65727333001053367881 52584907711670556013 53697817977846174064 83972241375657056057 82166370484403199890 96983520312774506326 12540698747158523863 66896648950445244523 05886116467109405077 16427171479924442928 17866458359124566529 24219022671055626321 07198403850962455444 84580156166097919133 62229893423380308135 73167176531330624919 30358907296290491560 70172427121883998797 Your code should contain a PHP function that, accepting the string of 400 numbers in input, is able to find the greatest product of four adjacent numbers in all the...
Week 4 Assignment HTML – Creating a Simple Web Page “HTML or HyperText Markup Language as...
Week 4 Assignment HTML – Creating a Simple Web Page “HTML or HyperText Markup Language as it is formally known is the main markup language for creating web pages and other information that can be displayed in a webbrowser”. It was created by Tim Berners-Lee in 1989 as a user friendly way of sharing information on the Internet. http://en.wikipedia.org/wiki/HTML Assignment Instructions - Create a simple HTML Web Page that includes hyperlinks to three of your favorite websites. Use the online...
Write an HTML file for a web page that contains the items below. Use an internal...
Write an HTML file for a web page that contains the items below. Use an internal style sheet to specify all fonts, sizes, colors, and any other aspects of the presentation. Your page should contain the following items: 1) A header with white text on dark green background (just for the header, not the entire page), in Impact font, bold, and centered. 2) Two paragraphs of text, each with dark gray text in Tahoma font, on a light blue background,...
Make a modest or simple Web page using Python flask. The basic components of HTML should...
Make a modest or simple Web page using Python flask. The basic components of HTML should be included. The Web page should have at least 3 Headings(<h1>), paragraph (<p>), comments (<!-- -->), ordered list, unordered list, three links to website, and should display time & date. Example: <html>     <head>         <title>Page Title</title>     </head> <body>     ..new page content.. </body> </html>
Assume that there is an image “fewa.jpg” in the root of the HTML folder. Write HTML...
Assume that there is an image “fewa.jpg” in the root of the HTML folder. Write HTML code to insert that image with appropriate alternative text. Also, apply an appropriate title to the image.?
1. An HTML document that’s generated by a web application is a ________________________ web page. 2....
1. An HTML document that’s generated by a web application is a ________________________ web page. 2. An easy way to log the progress of an application in Chrome’s Console panel is to insert __________________ methods at critical points in the code. 3. The childNodes property of a DOM object returns a/an ______________________ of the child nodes for that object. 4. The ___________________ method of an array can be used to concatenate the elements of the array into a single string.​...
Please write "my account" page program by using HTML and CSS
Please write "my account" page program by using HTML and CSS
Develop a personal web page for yourself using HTML, CSS, and Javascript Use the following HTML...
Develop a personal web page for yourself using HTML, CSS, and Javascript Use the following HTML tags to design your webpage: <h1>...</h1>,<h3>...</h3>, <h6>...</h6>, <p>...</p>, <b>...</b>, <i>...</i>, <a>...</a>, <img...>, <table>... </table>, <div>...</div>, <form>...</form>, <input type="text">, and <input type= "submit"> Use an external css to change the default style of your webpage. You must use at least one element selector, one id selector, and one class selector Using text input and submit button, allow the user to change the background color of...
use CSS, java and HTML to make a charity admin page. It's a web page after...
use CSS, java and HTML to make a charity admin page. It's a web page after you log in to your account. I can have personal information, the amount of money donated, the children who have received charity, and some blogs. In fact, all the things are what I want. But you are free to do whatever You like, even if you don't say what I say. I just need a charity Admin page for charity User.Don't ask me for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT